package com.example.sunmiv1.activity;

import android.Manifest;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
 
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.widget.ContentLoadingProgressBar;
import androidx.fragment.app.FragmentActivity;

import android.text.Editable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.widget.Button;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.sunmiv1.BuildConfig;
import com.example.sunmiv1.R;
import com.example.sunmiv1.adapter.CollectingSilverClassificationAdapter;
import com.example.sunmiv1.adapter.CollectingSilverGoodsAdapter;
import com.example.sunmiv1.adapter.CollectingSilverSelectedAdapter;
import com.example.sunmiv1.adapter.SkuAdapter;
import com.example.sunmiv1.base.bean;
import com.example.sunmiv1.dialog.SilverDiscountDialog;
import com.example.sunmiv1.dialog.VipLoginDialog;
import com.example.sunmiv1.entity.GiftGoodsInfo;
import com.example.sunmiv1.entity.GoodBean;
import com.example.sunmiv1.entity.LoginEntity;
import com.example.sunmiv1.entity.NFCBean;
import com.example.sunmiv1.entity.VipListBean;
import com.example.sunmiv1.entity.good.NewGoodInfo;
import com.example.sunmiv1.http.HttpListener;
import com.example.sunmiv1.http.HttpManager;
import com.example.sunmiv1.listener.AdapterItemClickListener;
import com.example.sunmiv1.scan.InfraredScanActivity;
import com.example.sunmiv1.utils.ByteArrayTohexHepler;
import com.example.sunmiv1.utils.GsonTools;
import com.example.sunmiv1.utils.KotlinUtils;
import com.example.sunmiv1.utils.LogUtil;
import com.example.sunmiv1.utils.MathUtil;
import com.example.sunmiv1.utils.Tools;
import com.example.sunmiv1.utils.net.ACache;
import com.example.sunmiv1.utils.net.Common;
import com.example.sunmiv1.utils.net.GsonUtils;
import com.example.sunmiv1.utils.net.HttpUtils;
import com.example.sunmiv1.utils.net.LoadingDialog;
import com.example.sunmiv1.utils.net.TextCallBack;
import com.example.sunmiv1.utils.zxing.Constant;
import com.example.sunmiv1.utils.zxing.activity.CaptureActivity;
import com.example.sunmiv1.vm.CollectingSilverViewModel;
import com.google.gson.Gson;
import com.luck.picture.lib.tools.ToastUtils;
import com.zhy.autolayout.widget.AutoConstraintLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.example.sunmiv1.utils.ByteArrayTohexHepler.ByteArrayToHexString;
import static com.example.sunmiv1.utils.ByteArrayTohexHepler.flipHexStr;
import static java.util.regex.Pattern.compile;

import net.nyx.printerservice.print.MemoryCacheManager;

/**
 * 收銀頁面
 */
public class CollectingSilverActivity extends FragmentActivity {

    @BindView(R.id.title_back)
    ImageView titleBack;
    @BindView(R.id.title_title)
    TextView titleTitle;
    @BindView(R.id.collectingSilver_scavenging)
    ImageView collectingSilverScavenging;
    @BindView(R.id.collectingSilver_classification_listView)
    ListView collectingSilverClassificationListView;
    @BindView(R.id.collectingSilver_goods_listView)
    ListView collectingSilverGoodsListView;
    @BindView(R.id.collectingSilver_num)
    TextView collectingSilverNum;
    @BindView(R.id.collectingSilver_price)
    TextView collectingSilverPrice;
    @BindView(R.id.collectingSilver_settlement)
    TextView collectingSilverSettlement;
    @BindView(R.id.collectingSilver_empty)
    TextView collectingSilverEmpty;
    @BindView(R.id.collectingSilver_selected_listView)
    ListView collectingSilverSelectedListView;


    @BindView(R.id.collectingSilver_selected_linear)
    LinearLayout collectingSilverSelectedLinear;


    @BindView(R.id.collectingSilver_shopCar)
    ImageView collectingSilverShopCar;
    @BindView(R.id.collectingSilver_weigh_name)
    TextView collectingSilverWeighName;
    @BindView(R.id.collectingSilver_weigh_barcode)
    TextView collectingSilverWeighBarcode;
    @BindView(R.id.collectingSilver_weigh_freightNumber)
    TextView collectingSilverWeighFreightNumber;
    @BindView(R.id.collectingSilver_weigh_num)
    EditText collectingSilverWeighNum;
    @BindView(R.id.collectingSilver_weigh_sure)
    TextView collectingSilverWeighSure;
    @BindView(R.id.collectingSilver_weigh_inner)
    LinearLayout collectingSilverWeighInner;
    @BindView(R.id.collectingSilver_weigh_linear)
    LinearLayout collectingSilverWeighLinear;
    @BindView(R.id.collectingSilver_noCode_off)
    ImageView collectingSilverNoCodeOff;
    @BindView(R.id.collectingSilver_noCode_price)
    EditText collectingSilverNoCodePrice;
    @BindView(R.id.collectingSilver_noCode_kg)
    EditText collectingSilverNoCodeKg;
    @BindView(R.id.collectingSilver_noCode_noWeight)
    RadioButton collectingSilverNoCodeNoWeight;
    @BindView(R.id.collectingSilver_noCode_weight)
    RadioButton collectingSilverNoCodeWeight;
    @BindView(R.id.collectingSilver_noCode_cancel)
    TextView collectingSilverNoCodeCancel;
    @BindView(R.id.collectingSilver_noCode_sure)
    TextView collectingSilverNoCodeSure;
    @BindView(R.id.collectingSilver_noCode_linear)
    LinearLayout collectingSilverNoCodeLinear;
    @BindView(R.id.collectingSilver_noCode)
    LinearLayout collectingSilverNoCode;
    @BindView(R.id.iv_collectingSilver_underline)
    ImageView ivCollectingSilverUnderline;
    @BindView(R.id.et_collectingSilver_underline)
    EditText etCollectingSilverUnderline;
    @BindView(R.id.tv_collectingSilver_underline_cancel)
    TextView tvCollectingSilverUnderlineCancel;
    @BindView(R.id.tv_collectingSilver_underline_confirm)
    TextView tvCollectingSilverUnderlineConfirm;
    @BindView(R.id.sku_price)
    TextView skuPrice;
    @BindView(R.id.lv_specification_name)
    ListView lvSpecificationName;
    @BindView(R.id.sku_picture)
    ImageView skuPicture;
    @BindView(R.id.sku_name)
    TextView skuName;
    @BindView(R.id.close_choose)
    ImageView closeChoose;
    @BindView(R.id.ll_sku)
    LinearLayout llSku;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;

    @BindView(R.id.collectingSilver_addSku_off)
    ImageView collectingSilverAddSkuOff;
    @BindView(R.id.collectingSilver_addSku_et)
    EditText collectingSilverAddSkuEt;
    @BindView(R.id.collectingSilver_addSku_cancel)
    TextView collectingSilverAddSkuCancel;
    @BindView(R.id.collectingSilver_addSku_confirm)
    TextView collectingSilverAddSkuConfirm;
    @BindView(R.id.collectingSilver_addSku_linear)
    LinearLayout collectingSilverAddSkuLinear;
    @BindView(R.id.collectingSilver_search_et)
    EditText collectingSilverSearchEt;
    @BindView(R.id.collectingSilver_search)
    ImageView collectingSilverSearch;
    @BindView(R.id.collectingSilver_vipLogin)
    LinearLayout collectingSilverVipLogin;
    @BindView(R.id.collectingSilver_vipLogin_close)
    ImageView collectingSilverVipLoginClose;
    @BindView(R.id.collectingSilver_vipLogin_edit)
    EditText collectingSilverVipLoginEdit;
    @BindView(R.id.collectingSilver_vipLogin_scavenging)
    ImageView collectingSilverVipLoginScavenging;
    @BindView(R.id.collectingSilver_vipLogin_sure)
    TextView collectingSilverVipLoginSure;
    @BindView(R.id.collectingSilver_vipLogin_linear)
    LinearLayout collectingSilverVipLoginLinear;
    @BindView(R.id.ll_collectingSilver_underline)
    LinearLayout llCollectingSilverUnderline;
    @BindView(R.id.collectingSilver_vipInfo_close)
    ImageView collectingSilverVipInfoClose;
    @BindView(R.id.collectingSilver_cardNum)
    TextView collectingSilverCardNum;
    @BindView(R.id.collectingSilver_name)
    TextView collectingSilverName;
    @BindView(R.id.collectingSilver_grade)
    TextView collectingSilverGrade;
    @BindView(R.id.collectingSilver_integral)
    TextView collectingSilverIntegral;
    @BindView(R.id.collectingSilver_balance)
    TextView collectingSilverBalance;
    @BindView(R.id.collectingSilver_vipInfo_sure)
    TextView collectingSilverVipInfoSure;
    @BindView(R.id.collection_select_title)
    TextView collectionSelectTitle;

    // 會員信息
    @BindView(R.id.collectingSilver_vipInfo_linear)
    LinearLayout collectingSilverVipInfoLinear;

    @BindView(R.id.collectingSilver_discount)
    TextView collectingSilverDiscount;
    @BindView(R.id.collectingSilver_noCode_company)
    EditText collectingSilverNoCodeCompany;
    @BindView(R.id.collectingSilver_noCode_spinnerCompany)
    Spinner collectingSilverNoCodeSpinnerCompany;
    @BindView(R.id.collectingSilver_chooseGiftNum)
    TextView collectingSilverChooseGiftNum;
    @BindView(R.id.collectingSilver_chooseGift)
    LinearLayout collectingSilverChooseGift;
    @BindView(R.id.collectingSilver_credit)
    TextView collectingSilverCreditMoney;
    @BindView(R.id.linear_collectingSilver_credit)
    LinearLayout linearCollectingSilverCredit;
    @BindView(R.id.load_view)
    AutoConstraintLayout mLoadView;
    @BindView(R.id.load_icon)
    ContentLoadingProgressBar mLoadIcon;
    @BindView(R.id.cart_view)
    LinearLayout mCartView;

    @BindView(R.id.sku_remove_bt)
    View mSkuRemoveBt;
    @BindView(R.id.sku_add_bt)
    View mSkuAddBt;
    @BindView(R.id.sku_remove_icon)
    View mSkuRemoveIcon;
    @BindView(R.id.sku_add_icon)
    View mSkuAddBtIcon;
    @BindView(R.id.sku_count_edit)
    EditText mSkuEditView;

    @BindView(R.id.number_dialog)
    AutoConstraintLayout mNumberDialog;
    @BindView(R.id.number_content_view)
    AutoConstraintLayout mNumberContentView;
    @BindView(R.id.number_edit)
    EditText mNumberEdit;
    @BindView(R.id.number_bt)
    View mNumberBt;

    @BindView(R.id.discount_view)
    AutoConstraintLayout mDiscountView;
    @BindView(R.id.discount_edit_title)
    View mDiscountTitleView;
    @BindView(R.id.edit_discount_view)
    AutoConstraintLayout mDiscountContentView;
    @BindView(R.id.discount_edit_name)
    TextView discount_edit_name;
    @BindView(R.id.discount_edit_price)
    TextView discount_edit_price;
    @BindView(R.id.edit_discount_edit)
    TextView edit_discount_edit;
    // @BindView(R.id.discount_edit_button_100)
    // TextView discount_edit_button_100;
    @BindView(R.id.edit_discount_amount_edit)
    TextView edit_discount_amount_edit;
    @BindView(R.id.edit_discount_bt)
    View edit_discount_bt;
    @BindView(R.id.edit_discount_tip)
    TextView edit_discount_tip;

    private List<Button> discountButtons = new ArrayList<>();

    private Context context;
    private GoodBean goodBean;
    private GoodBean.DataBean.GoodsBean mUpdateItem=null;
    private List<GoodBean.DataBean> classList = new ArrayList<>();//所有的分類的集合
    private List<GoodBean.DataBean.GoodsBean> goodList = new ArrayList<>();//當前分類下的商品集合
    private List<GoodBean.DataBean.GoodsBean> selectList = new ArrayList<>();//已經選擇的商品的集合
    private CollectingSilverClassificationAdapter classificationAdapter;//商品分類的適配器
    private CollectingSilverGoodsAdapter goodsAdapter;//商品的適配器
    private CollectingSilverSelectedAdapter selectedAdapter;//購物車的適配器
    private Intent intent;
    private ACache aCache;
    private LoadingDialog loadingDialog;


    private int class_index = 0;//掃描商品條形碼添加商品
    private int goods_index = 0;//掃描商品條形碼添加商品
    private int sku_index = 9999;//
    private int allNum = 0;//選擇的商品的數量
    private int giftGoodsNum = 0;//贈送商品的數量
    private HashMap<String,Integer> mGiftGoodsNumMap=new HashMap<>();
    private double allPrice = 0;//選擇的商品的總價格
    private int allIntegral = 0;
    private double mVipDiscountMoney = 0;
    DecimalFormat decimalFormat = new DecimalFormat("0.00");

    private int weighFlag = 0;//1:直接點擊商品裏面的 2:點擊購物車裏面的
    private int weighPosition = 0;//掃碼添加商品，第幾個分類
    private int weighIndex = 0;//點擊的是第幾個商品
    private static final String TAG = "CollectingSilverActivity";

    public static CollectingSilverActivity collectingSilverActivity;

    public static int isVip = 0;
    /*獲取會員信息*/
//    private static VipListBean vipinfoBean;
    public static VipListBean.InfoBean infoBean;

    private int page = 1;

    private List<String> unitList = new ArrayList<>();//單位集合
    private int unitIndex = 0;

    //nfc
    private NfcAdapter mNfcAdapter;
    private PendingIntent pi;
    private boolean isSupportNfc, isOpenNfc;
    //判斷商品是搜索添加商品還是點擊添加商品
    private boolean isSearchGoods = false;
    public static String vipDiscount = "";
    private LoginEntity loginEntity;

    private CollectingSilverViewModel mViewModel;
 
    protected void onCreateButton(GoodBean.DataBean.GoodsBean item) { 
        // 打印
        Log.e(TAG, "onCreateButton: " + item);

        // 初始化按钮并添加到列表中
        discountButtons.add(findViewById(R.id.discount_edit_button_100));
        discountButtons.add(findViewById(R.id.discount_edit_button_95));
        discountButtons.add(findViewById(R.id.discount_edit_button_90));
        discountButtons.add(findViewById(R.id.discount_edit_button_85));
        discountButtons.add(findViewById(R.id.discount_edit_button_80));
        discountButtons.add(findViewById(R.id.discount_edit_button_75));
        discountButtons.add(findViewById(R.id.discount_edit_button_70));
        discountButtons.add(findViewById(R.id.discount_edit_button_65));
        discountButtons.add(findViewById(R.id.discount_edit_button_60));
        discountButtons.add(findViewById(R.id.discount_edit_button_55));
        discountButtons.add(findViewById(R.id.discount_edit_button_50));
        discountButtons.add(findViewById(R.id.discount_edit_button_45));
        discountButtons.add(findViewById(R.id.discount_edit_button_40));
        discountButtons.add(findViewById(R.id.discount_edit_button_35));
        discountButtons.add(findViewById(R.id.discount_edit_button_30));
        discountButtons.add(findViewById(R.id.discount_edit_button_25));
        discountButtons.add(findViewById(R.id.discount_edit_button_20));
        discountButtons.add(findViewById(R.id.discount_edit_button_15));
        discountButtons.add(findViewById(R.id.discount_edit_button_10));
        discountButtons.add(findViewById(R.id.discount_edit_button_5));

        // 为每个按钮设置点击事件监听器
        for (Button button : discountButtons) {
            button.setOnClickListener(new View.OnClickListener() {
                 
                public void onClick(View v) {
                    // 打印标示
                    Log.e(TAG, "Button clicked: " + button.getText());
                
                    // 取消所有按钮的选中状态
                    for (Button b : discountButtons) {
                        b.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.default_button_background));
                    }
                    // 设置当前点击按钮为选中状态
                    v.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.selected_button_background));

                     // 获取折扣值并更新
            try {
                String discountText = ((Button) v).getText().toString().replace("折", "");
                double discountValue = Double.parseDouble(discountText) / 100.0;

                edit_discount_edit.setText(discountText + "");
                edit_discount_bt.setSelected(true);
                double value = discountValue;
                Log.e("discountValuediscountValue", discountValue + "");
                initDiscountView(item, value);
            } catch (NumberFormatException e) {
                Log.e(TAG, "Invalid discount text: ");
                // Toast.makeText(context, "折扣值无效，请输入正确的折扣", Toast.LENGTH_SHORT).show();
            }
                   
                }
            });
        }
    }

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:
                    long startTime = System.currentTimeMillis();
                    int size = 0;
                    if (classList.size() == 0) {
                        classList.add(new GoodBean.DataBean("0", "常用商品", new ArrayList<>()));
                    }
                    for (int i = 0; i < goodBean.getData().size(); i++) {
                        int index = 0;
                        boolean flag = false;
                        for (int t = 0; t < classList.size(); t++) {
                            if (goodBean.getData().get(i).getId().equals(classList.get(t).getId())) {
                                flag = true;
                                index = t;
                            }
                        }
                        if (flag) {
                            for (int s = 0; s < goodBean.getData().get(i).getGoods().size(); s++) {
                                size++;
                                goodBean.getData().get(i).getGoods().get(s).setAgoods_count(1.0);
                                goodBean.getData().get(i).getGoods().get(s).setSku_discount(1);
                                goodBean.getData().get(i).getGoods().get(s).setSpell_name(
                                        Tools.getPinYinHeadChar(goodBean.getData().get(i).getGoods().get(s).getGoods_name()));
                                if ("0".equals(goodBean.getData().get(i).getId())) {
                                    goodList.add(goodBean.getData().get(i).getGoods().get(s));
                                }

                                goodBean.getData().get(i).getGoods().get(s).setGift_id("");
                                goodBean.getData().get(i).getGoods().get(s).setIs_gift_good(0);

                                classList.get(index).getGoods().add(goodBean.getData().get(i).getGoods().get(s));
                            }
                        } else {
                            for (int s = 0; s < goodBean.getData().get(i).getGoods().size(); s++) {
                                size++;
                                goodBean.getData().get(i).getGoods().get(s).setAgoods_count(1.0);
                                goodBean.getData().get(i).getGoods().get(s).setSku_discount(1);
                                goodBean.getData().get(i).getGoods().get(s).setSpell_name(Tools.getPinYinHeadChar(goodBean.getData().get(i).getGoods().get(s).getGoods_name()));
                                if (!"0".equals(goodBean.getData().get(i).getId())) {
                                    goodBean.getData().get(i).getGoods().get(s).setC_id(goodBean.getData().get(i).getId());
                                }

                                goodBean.getData().get(i).getGoods().get(s).setGift_id("");
                                goodBean.getData().get(i).getGoods().get(s).setIs_gift_good(0);
                            }
                            classList.add(goodBean.getData().get(i));
                        }
                    }
                    long endTime = System.currentTimeMillis();
                    if (size >= goodBean.getLimit()) {
                        page++;
                        GetGoodList(classList.get(classList.size() - 1).getGoods().get(
                                classList.get(classList.size() - 1).getGoods().size() - 1).getId());
                    } else {
                        loadingDialog.dismiss();
                        dismissLoad();
                        if (classList.size() > 0 && classList.get(0).getGoods().size() == 0) {
                            classList.remove(0);
                        }
                        if (goodList.size() == 0 && classList.size() > 0) {
                            for (int i = 0; i < classList.get(0).getGoods().size(); i++) {
                                goodList.add(classList.get(0).getGoods().get(i));
                            }
                        }
                    }
                    setClassificationAdapter();
                    setGoodsAdapter();
                    break;
                case 2:
                    loadingDialog.dismiss();
                    dismissLoad();
                    break;
                case 3:
                    if (infoBean != null) {
                        HttpManager.INSTANCE.getUserVipLabel(infoBean.getId(), new HttpListener<String>() {
                            @Override
                            public void onSucess(@Nullable String s) {
                                collectingSilverVipLoginLinear.setVisibility(View.GONE);
                                collectingSilverVipInfoLinear.setVisibility(View.VISIBLE);
//                        infoBean = vipinfoBean.getInfo().get(0);
                                collectingSilverCardNum.setText(infoBean.getCardnum());
                                collectingSilverName.setText(infoBean.getName());
                                collectingSilverGrade.setText(infoBean.getGrade_name());
                                collectingSilverIntegral.setText(infoBean.getIntegral());
                                collectingSilverBalance.setText(infoBean.getBalance());
                                collectingSilverDiscount.setText(infoBean.getDiscount() + "");
                                vipDiscount = infoBean.getDiscount() + "";
                                View labelView=findViewById(R.id.collectingSilver_label);
                                TextView labelTv=findViewById(R.id.collectingSilver_label_tv);
                                if(s.isEmpty()){
                                    labelView.setVisibility(View.GONE);
                                }else{
                                    labelView.setVisibility(View.VISIBLE);
                                }
                                labelTv.setText(s);
                            }

                            @Override
                            public void onError(@NonNull String msg) {
                                isVip = 0;
                                infoBean = null;
                                vipDiscount = "";
                                setGoodsAdapter();
                                countMoney();
                            }
                        });
                    }
                    break;
                case 4:
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_collecting_silver);
        context = this;
        mViewModel=new CollectingSilverViewModel(this);
        mViewModel.init();
        EventBus.getDefault().register(this);
        collectingSilverActivity = this;
        aCache = ACache.get(context);
        aCache.put("placeAnOrder", "1");//是否可以下單 1:可以 0:不可以
        Gson gson = new Gson();
        loginEntity = gson.fromJson(aCache.getAsString("loginInfo"), LoginEntity.class);
        loadingDialog = new LoadingDialog(context);
        ButterKnife.bind(this);
        titleTitle.setText(R.string.collectingSilverTitle);
        collectingSilverChooseGiftNum.setText("(" + giftGoodsNum + "/" + aCache.getAsString("goods_gifts_num") + ")");
        if ("0".equals(aCache.getAsString("credit"))) {
            linearCollectingSilverCredit.setVisibility(View.INVISIBLE);
        } else {
            linearCollectingSilverCredit.setVisibility(View.VISIBLE);
        }

        //nfc
        PackageManager packageManager = this.getPackageManager();
        isSupportNfc = packageManager.hasSystemFeature(PackageManager.FEATURE_NFC);
        Log.e(TAG, "onCreate: isSupportNfc=" + isSupportNfc);
        if (isSupportNfc) {
            mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
            pi = PendingIntent.getActivity(this, 0, new Intent(this, getClass())
                    .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
            if (mNfcAdapter != null && !mNfcAdapter.isEnabled()) {
                isOpenNfc = false;
            } else {
                isOpenNfc = true;
            }
        }
        initData();
        initSpinner();
        initViewColor(); 
    }
    private void showLoad(){
        if(mLoadView.getVisibility()==View.VISIBLE){
            return;
        }
        mCartView.setVisibility(View.INVISIBLE);
        mLoadIcon.getIndeterminateDrawable().setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY);
        mLoadIcon.show();
        mLoadView.setVisibility(View.VISIBLE);
    }
    private void dismissLoad(){
        if(mLoadView.getVisibility()!=View.VISIBLE){
            return;
        }
        mCartView.setVisibility(View.VISIBLE);
        mLoadIcon.hide();
        mLoadView.setVisibility(View.INVISIBLE);
    }
    private void initSpinner() {
        unitList.add("kg");
        unitList.add("KG");
        unitList.add("斤");
        unitList.add("公斤");
        unitList.add("市斤");
        unitList.add("千克");
        unitList.add("g");
        unitList.add("G");
        unitList.add("克");
        //往會員來源Spinner中添加數據
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.spinner_item, unitList);  //創建一個數組適配器
        adapter.setDropDownViewResource(R.layout.dropdown_stytle);
        collectingSilverNoCodeSpinnerCompany.setAdapter(adapter);
        collectingSilverNoCodeSpinnerCompany.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                unitIndex = position;
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }

    private void initData() {
        collectingSilverClassificationListView.setOnItemClickListener((parent, view, position, id) -> {
            classificationAdapter.setSelect(position);
            class_index = position;
            goodList.clear();
            for (int i = 0; i < classList.get(position).getGoods().size(); i++) {
                goodList.add(classList.get(position).getGoods().get(i));
            }
            //
            setGoodsAdapter();


        });
        collectingSilverSearchEt.setOnEditorActionListener((v, actionId, event) -> {
            if (getBoolean(actionId, event)) {
                selectGoods(collectingSilverSearchEt.getText().toString().trim());
            }
            return true;
        });
        collectingSilverWeighNum.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (charSequence.toString().contains(".")) {
                    if (-1 != charSequence.toString().indexOf(".", charSequence.toString().indexOf(".") + 1)) {
                        collectingSilverWeighNum.setText(charSequence.toString().
                                substring(0, charSequence.toString().length() - 1));
                        collectingSilverWeighNum.setSelection(charSequence.length() - 1);
                    } else {
                        if (charSequence.length() - 1 - charSequence.toString().indexOf(".") > 3) {
                            charSequence = charSequence.toString().subSequence(0, charSequence.toString().indexOf(".") + 4);
                            collectingSilverWeighNum.setText(charSequence);
                            collectingSilverWeighNum.setSelection(charSequence.length());
                        }
                    }
                }
                if (charSequence.toString().trim().substring(0).equals(".")) {
                    charSequence = "0" + charSequence;
                    collectingSilverWeighNum.setText(charSequence);
                    collectingSilverWeighNum.setSelection(2);
                }

                if (charSequence.toString().startsWith("0") && charSequence.toString().trim().length() > 1) {
                    if (!charSequence.toString().substring(1, 2).equals(".")) {
                        collectingSilverWeighNum.setText(charSequence.subSequence(1, 2));
                        collectingSilverWeighNum.setSelection(1);
                        return;
                    }
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!TextUtils.isEmpty(editable.toString())) {
                    if (Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$").matcher(editable.toString()).matches())
                        if (Double.parseDouble(editable.toString().trim()) > 1000) {
                            collectingSilverWeighNum.setText("1000.00");
                        }
                }
            }
        });
        collectingSilverNoCodeKg.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (charSequence.toString().contains(".")) {
                    if (-1 != charSequence.toString().indexOf(".", charSequence.toString().indexOf(".") + 1)) {
                        collectingSilverNoCodeKg.setText(charSequence.toString().
                                substring(0, charSequence.toString().length() - 1));
                        collectingSilverNoCodeKg.setSelection(charSequence.length() - 1);
                    } else {
                        if (charSequence.length() - 1 - charSequence.toString().indexOf(".") > 3) {
                            charSequence = charSequence.toString().subSequence(0, charSequence.toString().indexOf(".") + 4);
                            collectingSilverNoCodeKg.setText(charSequence);
                            collectingSilverNoCodeKg.setSelection(charSequence.length());
                        }
                    }
                }
                if (charSequence.toString().trim().substring(0).equals(".")) {
                    charSequence = "0" + charSequence;
                    collectingSilverNoCodeKg.setText(charSequence);
                    collectingSilverNoCodeKg.setSelection(2);
                }

                if (charSequence.toString().startsWith("0") && charSequence.toString().trim().length() > 1) {
                    if (!charSequence.toString().substring(1, 2).equals(".")) {
                        collectingSilverNoCodeKg.setText(charSequence.subSequence(1, 2));
                        collectingSilverNoCodeKg.setSelection(1);
                        return;
                    }
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        collectingSilverNoCodePrice.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (charSequence.toString().contains(".")) {
                    if (-1 != charSequence.toString().indexOf(".", charSequence.toString().indexOf(".") + 1)) {
                        collectingSilverNoCodePrice.setText(charSequence.toString().
                                substring(0, charSequence.toString().length() - 1));
                        collectingSilverNoCodePrice.setSelection(charSequence.length() - 1);
                    } else {

                        if (charSequence.length() - 1 - charSequence.toString().indexOf(".") > 2) {
                            charSequence = charSequence.toString().subSequence(0, charSequence.toString().indexOf(".") + 3);
                            collectingSilverNoCodePrice.setText(charSequence);
                            collectingSilverNoCodePrice.setSelection(charSequence.length());
                        }
                    }
                }
                if (charSequence.toString().trim().substring(0).equals(".")) {
                    charSequence = "0" + charSequence;
                    collectingSilverNoCodePrice.setText(charSequence);
                    collectingSilverNoCodePrice.setSelection(2);
                }

                if (charSequence.toString().startsWith("0") && charSequence.toString().trim().length() > 1) {
                    if (!charSequence.toString().substring(1, 2).equals(".")) {
                        collectingSilverNoCodePrice.setText(charSequence.subSequence(1, 2));
                        collectingSilverNoCodePrice.setSelection(1);
                        return;
                    }
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        collectingSilverNoCodeNoWeight.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (isChecked) {
                collectingSilverNoCodeKg.setVisibility(View.GONE);
                collectingSilverNoCodeCompany.setVisibility(View.VISIBLE);
                collectingSilverNoCodeSpinnerCompany.setVisibility(View.GONE);
            }
        });
        collectingSilverNoCodeWeight.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (isChecked) {
                collectingSilverNoCodeKg.setVisibility(View.VISIBLE);
                collectingSilverNoCodeCompany.setVisibility(View.GONE);
                collectingSilverNoCodeCompany.setText("");
                collectingSilverNoCodeSpinnerCompany.setVisibility(View.VISIBLE);
            }
        });
        collectingSilverSearchEt.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
//        collectingSilverSearchEt.setOnEditorActionListener((v, actionId, event) -> {
//            //當actionId == XX_SEND 或者 XX_DONE時都觸發
//            //或者event.getKeyCode == ENTER 且 event.getAction == ACTION_DOWN時也觸發
//            //注意，這是一定要判斷event != null。因爲在某些輸入法上會返回null。
//            if (actionId == EditorInfo.IME_ACTION_SEND
//                    || actionId == EditorInfo.IME_ACTION_DONE
//                    || (event != null && KeyEvent.KEYCODE_ENTER == event.getKeyCode() && KeyEvent.ACTION_DOWN == event.getAction())) {
//                selectGoods(collectingSilverSearchEt.getText().toString().trim());
//                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//                // 強制隱藏軟鍵盤
//                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
//            }
//            return false;
//        });
        collectingSilverSearchEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
//                String msg = collectingSilverSearchEt.getText().toString();
//                if (msg.length() == 0) {
//                    if (classList.size() == 0) {
//                        return;
//                    }
//                    goodList.clear();
//                    setGoodsAdapter();
//                    for (int i = 0; i < classList.size(); i++) {
//                        if (i == class_index) {
//                            for (int d = 0; d < classList.get(i).getGoods().size(); d++) {
//                                goodList.add(classList.get(i).getGoods().get(d));
//                            }
//                        }
//                    }
//                    setClassificationAdapter();
//                    setGoodsAdapter();
//                } else {
//                    if (!Tools.isGoodsCode(msg)) {
//                        goodList.clear();
//                        setGoodsAdapter();
//                        if (classList.size() > 0) {
//                            int i, size1 = classList.size();
//                            for (i = 0; i < size1; i++) {
//                                int t, size2 = classList.get(i).getGoods().size();
//                                for (t = 0; t < size2; t++) {
//                                    /*Log.e(TAG, "afterTextChanged: 名稱=====" + classList.get(i).getGoods().get(t).getGoods_name() +
//                                            "簡拼====" + classList.get(i).getGoods().get(t).getSpell_name());*/
//                                    if (classList.get(i).getGoods().get(t).getGoods_number().toLowerCase().contains(msg.toLowerCase())
//                                            || classList.get(i).getGoods().get(t).getSpell_name().contains(msg.toLowerCase()) ||
//                                            classList.get(i).getGoods().get(t).getGoods_name().contains(msg)) {
//                                        goodList.add(classList.get(i).getGoods().get(t));
//                                    }
//                                }
//                            }
//                            setGoodsAdapter();
//                        }
////                        searchFlag = true;
//                    }
//                }
            }
        });
    }

    private void setClassificationAdapter() {
        if (classificationAdapter == null) {
            classificationAdapter = new CollectingSilverClassificationAdapter(context, classList);
            collectingSilverClassificationListView.setAdapter(classificationAdapter);
            classificationAdapter.setSelect(0);
        } else {
            classificationAdapter.notifyDataSetChanged();
        }
    }

    private HashMap<Integer, String> mMap;
    //private boolean isGoods;

    GoodBean.DataBean.GoodsBean chooseGoodBean;
    private TextWatcher mSkuEditTextWatcher;
    private int mSkuCount=0;
    private void showSkuView(int index,GoodBean.DataBean.GoodsBean item){
        //Byron
        mUpdateItem=item;
        sku_index = 9999;
        goods_index = index;
        mMap = new HashMap<>();
        //isGoods = true;
        llSku.setVisibility(View.VISIBLE);
        GoodBean.DataBean.GoodsBean current=item;
        if(current==null){
            current=classList.get(class_index).getGoods().get(goods_index);
        }
        Glide.with(context).load(current.getGoods_img()).into(skuPicture);
        if(mSkuEditTextWatcher!=null){
            mSkuEditView.removeTextChangedListener(mSkuEditTextWatcher);
        }
        mSkuEditTextWatcher=new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                Log.e(TAG, "beforeTextChanged: ");
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                Log.e(TAG, "onTextChanged: ");
            }

            @Override
            public void afterTextChanged(Editable s) {
                Log.e(TAG, "afterTextChanged: ");
            }
        };
        final GoodBean.DataBean.GoodsBean c=current;
        mSkuAddBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!isSkuSubmit(c,true)){
                    return;
                }
                int count=Integer.parseInt(mSkuEditView.getEditableText().toString());
                count++;
                mSkuEditView.removeTextChangedListener(mSkuEditTextWatcher);
                mSkuEditView.setText(count+"");
                mSkuEditView.addTextChangedListener(mSkuEditTextWatcher);
            }
        });
        mSkuRemoveBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int count=Integer.parseInt(mSkuEditView.getEditableText().toString());
                if(count>1){
                    count--;
                    mSkuEditView.removeTextChangedListener(mSkuEditTextWatcher);
                    mSkuEditView.setText(count+"");
                    mSkuEditView.addTextChangedListener(mSkuEditTextWatcher);
                }
            }
        });
        if(mUpdateItem!=null){
            int v= new Double(mUpdateItem.getAgoods_count()).intValue();
            mSkuEditView.setText(v+"");
        }else {
            mSkuEditView.setText("1");
        }
        skuName.setText(current.getGoods_name());
        skuPrice.setText(current.getRetail_price());
        mSkuCount=Integer.parseInt(mSkuEditView.getEditableText().toString());
        mSkuEditView.addTextChangedListener(mSkuEditTextWatcher);
        if(current.getPricing_method().equals("1")){
            mSkuEditView.setVisibility(View.VISIBLE);
            mSkuRemoveBt.setVisibility(View.VISIBLE);
            mSkuAddBt.setVisibility(View.VISIBLE);
            mSkuRemoveIcon.setVisibility(View.VISIBLE);
            mSkuAddBtIcon.setVisibility(View.VISIBLE);
        }else {
            mSkuEditView.setVisibility(View.GONE);
            mSkuRemoveBt.setVisibility(View.GONE);
            mSkuAddBt.setVisibility(View.GONE);
            mSkuRemoveIcon.setVisibility(View.GONE);
            mSkuAddBtIcon.setVisibility(View.GONE);
        }
        SkuAdapter adapter = new SkuAdapter(context,current,mUpdateItem);
        adapter.onClicked((position, path) -> {
            //Toast.makeText(context, String.valueOf(position), Toast.LENGTH_SHORT).show();
            if(mUpdateItem==null){
                onItemSku(c,position,path);
            }else {
                onItemSku(c,position,path);
            }
        });
        lvSpecificationName.setAdapter(adapter);
    }

    private void onItemSku(GoodBean.DataBean.GoodsBean item,int position,String path){
        mMap.put(position, path);
        Log.e(TAG, "onItemSku: index="+position+" path="+path);
        Log.e(TAG, "onItemSku: map="+(new Gson().toJson(mMap)));
        Log.e(TAG, "onItemSku: size="+mMap.size()+";"+item.getSkuinfo().size()+" item="+(new Gson().toJson(item)));
        if (mMap.size() == item.getSkuinfo().size()) {
            String paths = "";
            for (int i = mMap.size() - 1; i >= 0; i--) {
                paths = mMap.get(i) + "," + paths;
            }
            paths = paths.substring(0, paths.length() - 1);
            boolean have = false;
            Log.e(TAG, "onItemSku: paths="+paths);
            for (int i = 0; i < item.getSkujson().size(); i++) {
                String res=item.getSkujson().get(i).getSku_res();
                Log.e(TAG, "onItemSku: item res="+res+" item="+(new Gson().toJson(item.getSkujson().get(i))));
                if (paths.equals(item.getSkujson().get(i).getSku_res()))     {
                    GoodBean.DataBean.GoodsBean.SkuListBean skuListBean = item.getSkujson().get(i);
                    GoodBean.DataBean.GoodsBean goods = item;
                    String price = "";
                    if (isVip == 1) {
                        if ("2".equals(infoBean.getPlus_type()) && "1".equals(item.getPlus_mem_status())) { //plus會員
                            if (!TextUtils.isEmpty(skuListBean.getPlus_price())) {
                                price = skuListBean.getPlus_price();
                            } else {
                                price = skuListBean.getRetail_price();
                            }
                        } else { //常規會員
                            if ("1".equals(item.getVip_retail_state())) {
                                if ("2".equals(skuListBean.getStore_mem_status())) {
                                    price = goods.getRetail_price();
                                } else {
                                    if (!TextUtils.isEmpty(skuListBean.getStore_mem_price())) {
                                        price = skuListBean.getStore_mem_price();
                                    } else {
                                        price = goods.getRetail_price();
                                    }
                                }
                            } else {
                                if ("2".equals(skuListBean.getStore_mem_status())) {
                                    price = goods.getRetail_price();
                                } else {
                                    if (!TextUtils.isEmpty(skuListBean.getStore_mem_price())) {
                                        price = skuListBean.getStore_mem_price();
                                    } else {
                                        price = goods.getRetail_price();
                                    }
                                }
                            }
                        }
                    } else {
                        price = skuListBean.getRetail_price();
                    }
                    skuPrice.setText(price);
                    have = true;
                    break;
                }
            }
            Log.e(TAG, "onItemSku: have="+have);
            if (have) {
                sku_index = 0;
            }
        }
    }

    private void setGoodsAdapter() {
        if (goodsAdapter == null) {
            goodsAdapter = new CollectingSilverGoodsAdapter(context, goodList);
            collectingSilverGoodsListView.setAdapter(goodsAdapter);
        } else {
            goodsAdapter.notifyDataSetChanged();
        }
        goodsAdapter.onclick((index, type) -> {
//            if (type == 1) {//執行添加
            GoodBean.DataBean.GoodsBean item=goodList.get(index);
            List<Integer> list=KotlinUtils.INSTANCE.getGoodItemIndex(classList,item);
            if(list.get(0)<0){
                return;
            }
            class_index=list.get(0);

            chooseGoodBean = new GoodBean.DataBean.GoodsBean(goodList.get(index));
            isSearchGoods = false;
            if (("2".equals(goodList.get(index).getAttribute_state()) || type==2) && (goodList.get(index).getSkujson() != null
                    && goodList.get(index).getSkujson().size() > 0)) {
                showSkuView(index,null);
            } else {
                int position1 = -1;
                if ("1".equals(goodList.get(index).getPricing_method())) {
                    if ("1".equals(goodList.get(index).getSerial_number_state())) {
                        boolean have = false;
                        for (int i = 0; i < selectList.size(); i++) {
                            if (goodList.get(index).getId().equals(selectList.get(i).getId()) &&
                                    goodList.get(index).getIs_gift_good() == selectList.get(i).getIs_gift_good()) {
                                have = true;
                                position1 = i;
                                break;
                            }
                        }
                        if (have) {

                            intent = new Intent(context, StringCodeOperationActivity.class);
                            intent.putExtra("good", selectList.get(position1));
                            intent.putExtra("operation", 1);
                            startActivityForResult(intent, 300);
                        } else {
                            intent = new Intent(context, StringCodeOperationActivity.class);
                            intent.putExtra("good", goodList.get(index));
                            intent.putExtra("operation", 1);
                            startActivityForResult(intent, 300);
                        }
                    } else {
                        if (selectList.size() == 0) {
                            selectList.add(goodList.get(index));
                        } else {
                            boolean have = false;
                            int position = 0;
                            for (int i = 0; i < selectList.size(); i++) {
                                if (goodList.get(index).getId().equals(selectList.get(i).getId()) &&
                                        goodList.get(index).getIs_gift_good() == selectList.get(i).getIs_gift_good()) {
                                    have = true;
                                    position = i;
                                    break;
                                }
                            }
                            if (have) {
                                selectList.get(position).setAgoods_count(goodList.get(index).getAgoods_count() == null ? 1 : goodList.get(index).getAgoods_count() + 1);
                            } else {
                                selectList.add(goodList.get(index));
                            }
                        }
                    }
                } else {
                    weighFlag = 1;
                    weighIndex = index;
                    collectingSilverWeighName.setText(goodList.get(index).getGoods_name());
                    collectingSilverWeighFreightNumber.setText(goodList.get(index).getGoods_number());
                    collectingSilverWeighBarcode.setText(goodList.get(index).getGoods_code());
                    collectingSilverWeighNum.setText(goodList.get(index).getAgoods_count() == null ? "" : String.valueOf(goodList.get(index).getAgoods_count()));
                    collectingSilverWeighLinear.setVisibility(View.VISIBLE);
                    collectingSilverWeighNum.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            collectingSilverWeighNum.requestFocus();
                            collectingSilverWeighNum.setSelection(collectingSilverWeighNum.getText().toString().length());
                        }
                    }, 500);
                }
            }
            setGoodsAdapter();
            countMoney();
        });
    }

// setSelectedAdapter 方法用于设置和更新购物车中已选择商品的适配器
    private void setSelectedAdapter() {
        if (selectedAdapter == null) {
            selectedAdapter = new CollectingSilverSelectedAdapter(context, selectList, loginEntity);
            collectingSilverSelectedListView.setAdapter(selectedAdapter);
        } else {
            selectedAdapter.notifyDataSetChanged();
        }
        selectedAdapter.onclick(new CollectingSilverSelectedAdapter.Util() {
            @Override
            public void util(int index, int type) {
                //type==1增加商品
                if (type == 1) {
                    if (selectList.get(index).getIs_gift_good() == 1) {
                        if (giftGoodsNum >= Integer.parseInt(aCache.getAsString("goods_gifts_num"))) {
                            Toast.makeText(context, "不能繼續增加了", Toast.LENGTH_SHORT).show();
                            return;
                        }
                        giftGoodsNum++;
                    }
                    if ("1".equals(selectList.get(index).getPricing_method())) {
                        selectList.get(index).setAgoods_count(selectList.get(index).getAgoods_count() == null ? 0.0 : selectList.get(index).getAgoods_count() + 1);
                        for (int i = 0; i < goodList.size(); i++) {
                            if (selectList.get(index).getId().equals(goodList.get(i).getId())) {
                                goodList.get(i).setAgoods_count(selectList.get(index).getAgoods_count());
                                break;
                            }
                        }
//                        allPrice += Double.parseDouble(selectList.get(index).getRetail_price());
                    } else {
                        weighFlag = 2;
                        weighIndex = index;
                        collectingSilverWeighName.setText(selectList.get(index).getGoods_name());
                        collectingSilverWeighFreightNumber.setText(selectList.get(index).getGoods_number());
                        collectingSilverWeighBarcode.setText(selectList.get(index).getGoods_code());
                        collectingSilverWeighNum.setText(selectList.get(index).getAgoods_count() == null ? "" : String.valueOf(selectList.get(index).getAgoods_count()));
                        collectingSilverWeighLinear.setVisibility(View.VISIBLE);
                        collectingSilverWeighNum.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                collectingSilverWeighNum.requestFocus();
                                collectingSilverWeighNum.setSelection(collectingSilverWeighNum.getText().toString().length());
                            }
                        }, 500);
                    }
                } else if (type == 2) { //減少商品
                    //串碼商品
                    if ("1".equals(selectList.get(index).getSerial_number_state())) {
                        selectList.remove(index);
                    } else {
                        if (selectList.get(index).getIs_gift_good() == 1) {
                            giftGoodsNum--;
                        }
                        if ("1".equals(selectList.get(index).getPricing_method())) {
                            if (selectList.get(index).getAgoods_count() >= 1) {
                                selectList.get(index).setAgoods_count(selectList.get(index).getAgoods_count() - 1);
                            }
                            for (int i = 0; i < goodList.size(); i++) {
                                if (selectList.get(index).getId().equals(goodList.get(i).getId())) {
                                    goodList.get(i).setAgoods_count(selectList.get(index).getAgoods_count());
                                    break;
                                }
                            }
                            if (selectList.get(index).getAgoods_count() == 0) {
                                selectList.remove(index);
                            }
                        } else {
                            weighFlag = 2;
                            weighIndex = index;
                            collectingSilverWeighName.setText(selectList.get(index).getGoods_name());
                            collectingSilverWeighFreightNumber.setText(selectList.get(index).getGoods_number());
                            collectingSilverWeighBarcode.setText(selectList.get(index).getGoods_code());
                            collectingSilverWeighNum.setText(selectList.get(index).getAgoods_count() == null ? "" : String.valueOf(selectList.get(index).getAgoods_count()));
                            collectingSilverWeighLinear.setVisibility(View.VISIBLE);
                        }
                        if (selectList.size() == 0) {
                            collectingSilverSelectedLinear.setVisibility(View.GONE);
                        }
                    }
                } else if (type == 3) {
                    intent = new Intent(context, StringCodeOperationActivity.class);
                    intent.putExtra("good", selectList.get(index));
                    intent.putExtra("operation", 1);
                    startActivityForResult(intent, 300);
                } else if (type == 4) {
                    selectList.remove(index);
                }else if (type == 5) {
                    GoodBean.DataBean.GoodsBean item=selectList.get(index);
                    List<Integer> list=KotlinUtils.INSTANCE.getGoodItemIndex(classList,item);
                    if(list.get(0)<0){
                        return;
                    }
                    class_index=list.get(0);
                    showSkuView(list.get(1),item);
                    Log.e(TAG, "util: 未找到");
                }else if (type == 6) {
                    GoodBean.DataBean.GoodsBean item=selectList.get(index);
                    showNumberDialog(item);
                }else if (type ==7) {
                    GoodBean.DataBean.GoodsBean item=selectList.get(index);
                    showDiscountView(item);
                }
                setSelectedAdapter();
                countMoney();
            }

            @Override
            public void refresh() {
                countMoney();
            }
        });
        setGoodsAdapter();
    }

    private void countMoney() {

        collectingSilverChooseGiftNum.setText("(" + giftGoodsNum + "/" + aCache.getAsString("goods_gifts_num") + ")");
        allPrice = 0;
        allNum = 0;
        allPrice = 0;//商品總金額
//        integralDiscount = 0;//會員積分抵扣
        mVipDiscountMoney = 0;//共優惠
        allIntegral = 0;
        int success = 0;
        for (int i = 0; i < selectList.size(); i++) {
            String originalPrice = "";
            double price = 0;
            int integral = 0;
            GoodBean.DataBean.GoodsBean goods = selectList.get(i);
            double vip_discount = 1;
            if (((isVip == 1 && "1".equals(goods.getVip_retail_state()) && (!"1".equals(goods.getPlus_mem_status()) || !"2".equals(infoBean.getPlus_type())))
                    || (isVip == 1 && "1".equals(goods.getVip_retail_state()) && !"".equals(goods.getCheng_price()))) && infoBean != null) {
                vip_discount = infoBean.getDiscount();
            }
            if ("2".equals(goods.getPricing_method())) {
                allNum += 1;
            } else {
                allNum += goods.getAgoods_count();
            }
            if (1 == goods.getIs_gift_good()) {
                continue;
            }
            if ("".equals(goods.getCheng_price())) {
                if (isVip == 1) {
                    if ("2".equals(infoBean.getPlus_type()) && "1".equals(goods.getPlus_mem_status())) { //plus會員
                        if (isSkuGood(i, selectList)) { //判斷規格商品
                            if (!TextUtils.isEmpty(goods.getSkujson().get(0).getPlus_price())) {
                                price = getVipPrice(isVip, goods, goods.getSkujson().get(0).getPlus_price());
                                originalPrice = goods.getSkujson().get(0).getPlus_price();
                                if (!TextUtils.isEmpty(goods.getSkujson().get(0).getPlus_mem_integral())) {
                                    integral += Integer.parseInt(goods.getSkujson().get(0).getPlus_mem_integral());
                                }
                            } else {
                                price = getVipPrice(isVip, goods, goods.getSkujson().get(0).getRetail_price());
                                originalPrice = goods.getSkujson().get(0).getRetail_price();
                            }
                        } else {
                            if (!TextUtils.isEmpty(goods.getPlus_price())) {
                                price = getVipPrice(isVip, goods, goods.getPlus_price());
                                originalPrice = goods.getPlus_price();
                                if (!TextUtils.isEmpty(goods.getPlus_mem_integral())) {
                                    integral += Integer.parseInt(goods.getPlus_mem_integral());
                                }

                            } else {
                                price = getVipPrice(isVip, goods, goods.getRetail_price());
                                originalPrice = goods.getRetail_price();
                            }
                        }
                    } else { //常規會員
                        if ("1".equals(goods.getVip_retail_state())) {
                            if (isSkuGood(i, selectList)) {
                                if ("2".equals(goods.getSkujson().get(0).getStore_mem_status())) {
                                    price = getVipPrice(isVip, goods, goods.getRetail_price());
                                    originalPrice = goods.getRetail_price();
                                } else {
                                    if (!TextUtils.isEmpty(goods.getSkujson().get(0).getStore_mem_price())) {
                                        price = getVipPrice(isVip, goods, goods.getSkujson().get(0).getStore_mem_price());
                                        originalPrice = goods.getSkujson().get(0).getStore_mem_price();
                                        if (!TextUtils.isEmpty(goods.getSkujson().get(0).getStore_mem_integral())) {
                                            integral += Integer.parseInt(goods.getSkujson().get(0).getStore_mem_integral());
                                        }
                                    } else {
                                        price = getVipPrice(isVip, goods, goods.getRetail_price());
                                        originalPrice = goods.getRetail_price();
                                    }
                                }
                            } else {
                                if ("2".equals(goods.getStore_mem_status())) {
                                    price = getVipPrice(isVip, goods, goods.getRetail_price());
                                    originalPrice = goods.getRetail_price();
                                } else {
                                    if (!TextUtils.isEmpty(goods.getStore_mem_price())) {
                                        price = getVipPrice(isVip, goods, goods.getStore_mem_price());
                                        originalPrice = goods.getStore_mem_price();
                                        if (!TextUtils.isEmpty(goods.getStore_mem_integral())) {
                                            Log.e("===========3805", "countMoney: integral=" + goods.getStore_mem_integral());
                                            integral += Integer.parseInt(goods.getStore_mem_integral());
                                        }
                                    } else {
                                        price = getVipPrice(isVip, goods, goods.getRetail_price());
                                        originalPrice = goods.getRetail_price();
                                    }
                                }
                            }
                        } else {
                            if (isSkuGood(i, selectList)) {
                                if ("2".equals(goods.getSkujson().get(0).getStore_mem_status())) {
                                    price = getVipPrice(isVip, goods, goods.getRetail_price());
                                    originalPrice = goods.getRetail_price();
                                } else {
                                    if (!TextUtils.isEmpty(goods.getSkujson().get(0).getStore_mem_price())) {
                                        price = getVipPrice(isVip, goods, goods.getSkujson().get(0).getStore_mem_price());
                                        originalPrice = goods.getSkujson().get(0).getStore_mem_price();
                                        if (!TextUtils.isEmpty(goods.getSkujson().get(0).getStore_mem_integral())) {
                                            integral += Integer.parseInt(goods.getSkujson().get(0).getStore_mem_integral());
                                        }
                                    } else {
                                        price = getVipPrice(isVip, goods, goods.getRetail_price());
                                        originalPrice = goods.getRetail_price();
                                    }
                                }
                            } else {
                                if ("2".equals(goods.getStore_mem_status())) {
                                    price = getVipPrice(isVip, goods, goods.getRetail_price());
                                    originalPrice = goods.getRetail_price();
                                } else {
                                    if (!TextUtils.isEmpty(goods.getStore_mem_price())) {
                                        price = Double.parseDouble(goods.getStore_mem_price());
                                        if (!TextUtils.isEmpty(goods.getStore_mem_integral())) {
                                            integral += Integer.parseInt(goods.getStore_mem_integral());
                                        }
                                    } else {
                                        price = Double.parseDouble(goods.getRetail_price());
                                    }
                                    originalPrice = price + "";
                                    price = getVipPrice(isVip, goods, price + "");
                                }
                            }
                        }
                    }
                } else {
                    if (isSkuGood(i, selectList)) {
                        if (goods.getSkujson().get(0).getRetail_price() != null &&
                                !TextUtils.isEmpty(goods.getSkujson().get(0).getRetail_price())) {
                            price = getVipPrice(0, goods, goods.getSkujson().get(0).getRetail_price());
                            originalPrice = goods.getSkujson().get(0).getRetail_price();
                        } else {
                            price = getVipPrice(0, goods, goods.getRetail_price());
                            originalPrice = goods.getRetail_price();
                        }
                    } else {
                        price = getVipPrice(0, goods, goods.getRetail_price());
                        originalPrice = goods.getRetail_price();
                    }
                }
                Log.e(TAG, "countMoney: 積分=" + integral);
                allPrice += MathUtil.mul(price, goods.getAgoods_count());
                mVipDiscountMoney += MathUtil.sub(doubleAndMul(originalPrice, goods.getAgoods_count() + ""), doubleAndMul(price + "", goods.getAgoods_count() + ""));
                allIntegral += MathUtil.mul(integral, goods.getAgoods_count());
                if ("1".equals(aCache.getAsString("manual_discount"))) {
                    double dis = goods.getSku_discount();
                    double p1 = doubleAndMul(originalPrice, "" + goods.getAgoods_count());
                    double p2 = MathUtil.mul(doubleAndMul(originalPrice, dis + ""), goods.getAgoods_count());
                    if (dis < Double.parseDouble(aCache.getAsString("manual_min_discount")) || dis > 1 ||
                            ((doubleAndMul(aCache.getAsString("manual_max_amount"), goods.getAgoods_count() + "") < MathUtil.sub(p1, p2)) || dis > 1)) {
                        success++;
                    }
                }
            } else {
                if (isVip == 1) {
                    price = MathUtil.mul(Double.parseDouble(goods.getCheng_price()), vip_discount);
                } else {
                    price = Double.parseDouble(goods.getCheng_price());
                }
                allPrice += price;
                mVipDiscountMoney += MathUtil.sub(Double.parseDouble(selectList.get(i).getCheng_price()), price);
                if ("1".equals(aCache.getAsString("manual_discount"))) {
                    double dis = goods.getSku_discount();
                    double p1 = Double.parseDouble(selectList.get(i).getCheng_price());
                    double p2 = price;
                    if (dis < Double.parseDouble(aCache.getAsString("manual_min_discount")) || dis > 1 ||
                            ((doubleAndMul(aCache.getAsString("manual_max_amount"), goods.getAgoods_count() + "") < MathUtil.sub(p1, p2) && Double.parseDouble(aCache.getAsString("manual_max_amount")) > 0) || dis > 1)) {
                        success++;
                    }
                }
            }

        }
        if ("1".equals(aCache.getAsString("manual_discount"))) {
            if (success == 0) {
                aCache.put("placeAnOrder", "1");//是否可以下單 1:可以 0:不可以
            } else {
                aCache.put("placeAnOrder", "0");//是否可以下單 1:可以 0:不可以
            }
        }
        mVipDiscountMoney = MathUtil.round(mVipDiscountMoney, 2);
        allPrice = Double.parseDouble(decimalFormat.format(allPrice));
        if ("1".equals(aCache.getAsString("marketing_methods"))) {
            allIntegral = 0;
        }
        String countValue="";
        if (mVipDiscountMoney > 0) {
            countValue=(getString(R.string.common) + allNum + getString(R.string.common1) + mVipDiscountMoney + ")");
        } else {
            countValue=(getString(R.string.common) + allNum + getString(R.string.goodsNum));
        }
        {
            SpannableStringBuilder builder = new SpannableStringBuilder(countValue);

//ForegroundColorSpan 为文字前景色，BackgroundColorSpan为文字背景色
            ForegroundColorSpan buleSpan = new ForegroundColorSpan(Color.parseColor("#a1a1a1"));
            ForegroundColorSpan buleSpan1;
            if(allNum<=0){
                buleSpan1 = new ForegroundColorSpan(Color.parseColor("#a1a1a1"));
            }else {
                buleSpan1 = new ForegroundColorSpan(getResources().getColor(R.color.collectingSilver_yellow));
            }
            ForegroundColorSpan blackSpan = new ForegroundColorSpan(Color.parseColor("#a1a1a1"));

            builder.setSpan(buleSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            builder.setSpan(buleSpan1, 1, 1+(allNum+"").length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
            builder.setSpan(blackSpan, 1+(allNum+"").length(), countValue.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            collectingSilverNum.setText(builder);
        }
        initViewColor();
        if (allIntegral > 0) {
            collectingSilverPrice.setText("$" + allPrice + "+" + allIntegral + getString(R.string.integral));
        } else {
            collectingSilverPrice.setText("$" + allPrice);
        }
        if (selectList.size() > 5) {
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) collectingSilverSelectedListView.getLayoutParams();
            layoutParams.height = Tools.getScreenHeight(context) / 3;
            collectingSilverSelectedListView.setLayoutParams(layoutParams);
        } else {
            ViewGroup.LayoutParams layoutParams = collectingSilverSelectedListView.getLayoutParams();
            layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
            collectingSilverSelectedListView.setLayoutParams(layoutParams);
        }
    }

    private boolean isSkuGood(int i, List<GoodBean.DataBean.GoodsBean> selectList) {
        return "2".equals(selectList.get(i).getAttribute_state()) &&
                selectList.get(i).getSkujson() != null &&
                selectList.get(i).getSkujson().size() > 0;
    }


    /**
     * 獲取會員價格
     */
    private double getVipPrice(int type, GoodBean.DataBean.GoodsBean position, String retail_price) {//type 0:普通用戶 1:會員
        double price = 0;
        //開啓門店折上折
        if ("1".equals(aCache.getAsString("store_manual_discount"))) {
            if (type == 1 && "1".equals(position.getVip_retail_state()) && ("2".equals(position.getPlus_mem_status()) ||
                    "1".equals(position.getPlus_mem_status()) && !"2".equals(infoBean.getPlus_type()))) {
                price = MathUtil.mul(Double.parseDouble(retail_price), infoBean.getDiscount());
            } else {
                price = Double.parseDouble(retail_price);
            }
            price = doubleAndMul(price + "", position.getSku_discount() + "");
        } else {
            if (position.getSku_discount() == 1) {
                if (type == 1 && "1".equals(position.getVip_retail_state()) && ("2".equals(position.getPlus_mem_status()) ||
                        "1".equals(position.getPlus_mem_status()) && !"2".equals(infoBean.getPlus_type()))) {
                    price = MathUtil.mul(Double.parseDouble(retail_price), infoBean.getDiscount());
                } else {
                    price = doubleAndMul(retail_price, position.getSku_discount() + "");
                }
            } else {
                price = doubleAndMul(retail_price, position.getSku_discount() + "");
            }
        }
        if (price < 0.01) {
            price = 0.01;
        }
        return price;
    }

    /**
     * 獲取兩數相乘的數
     */
    private double doubleAndMul(String retail_price, String vipDiscount) {
        return MathUtil.round(MathUtil.mul(Double.parseDouble(retail_price),
                Double.parseDouble(vipDiscount)), 2);
    }

    @OnClick({R.id.title_back, R.id.collectingSilver_scavenging, R.id.collectingSilver_settlement, R.id.collectingSilver_shopCar,
            R.id.collectingSilver_empty, R.id.collectingSilver_selected_linear,
            R.id.collectingSilver_weigh_sure, R.id.collectingSilver_weigh_linear,
            /*添加無碼商品*/
            R.id.collectingSilver_noCode_linear, R.id.collectingSilver_noCode_cancel, R.id.collectingSilver_noCode_sure, R.id.collectingSilver_noCode_off,
            R.id.collectingSilver_noCode, /*R.id.collectingSilver_underline,*/R.id.collectingSilver_search,
            R.id.iv_collectingSilver_underline, R.id.tv_collectingSilver_underline_cancel, R.id.tv_collectingSilver_underline_confirm, R.id.ll_collectingSilver_underline,
            R.id.close_choose, R.id.ll_sku,
            R.id.tv_confirm,
            /*添加規格稱重商品*/
            R.id.collectingSilver_addSku_linear, R.id.collectingSilver_addSku_off, R.id.collectingSilver_addSku_cancel, R.id.collectingSilver_addSku_confirm,
            R.id.collectingSilver_vipLogin, R.id.collectingSilver_vipLogin_close, R.id.collectingSilver_vipLogin_linear,
            R.id.collectingSilver_vipLogin_scavenging, R.id.collectingSilver_vipLogin_sure,
            R.id.collectingSilver_vipInfo_close, R.id.collectingSilver_vipInfo_sure, R.id.collectingSilver_vipInfo_linear,
            R.id.collectingSilver_chooseGift})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.collectingSilver_chooseGift:
                if ("0".equals(aCache.getAsString("goods_gifts_auth"))) {
                    Toast.makeText(context, "沒用贈送商品的權限", Toast.LENGTH_SHORT).show();
                    return;
                }
                intent = new Intent(context, ChooseGiftGoodsActivity.class);
                intent.putExtra("giftGoodsNum", giftGoodsNum);
                intent.putExtra("choose_list", (Serializable) gifts);
                startActivityForResult(intent, 200);
                break;
            case R.id.collectingSilver_vipInfo_close:
                collectingSilverVipInfoLinear.setVisibility(View.GONE);
                isVip = 0;
                infoBean = null;
                vipDiscount = "";
//                vipinfoBean = null;
                setSelectedAdapter();
                countMoney();
                break;
            case R.id.collectingSilver_vipInfo_sure:
                isVip = 1;
//                collectingSilverVipLogin.setText("退出");
                setGoodsAdapter();
                setSelectedAdapter();
                countMoney();
                collectingSilverVipInfoLinear.setVisibility(View.GONE);
                break;
            case R.id.collectingSilver_vipInfo_linear:
                break;

            case R.id.collectingSilver_vipLogin:
                if (isVip == 0) {
                    VipLoginDialog.newInstance()
                            .callback(o -> {
                                infoBean = (VipListBean.InfoBean) o;
                                Message msg = new Message();
                                msg.what = 3;
                                handler.sendMessage(msg);
                            })
                            .startShow(getSupportFragmentManager(), "")
                            .setCancelable(false);
                } else {
                    isVip = 0;
                    infoBean = null;
                    vipDiscount = "";
                    setGoodsAdapter();
                    Toast.makeText(context, "退出成功", Toast.LENGTH_SHORT).show();
                    countMoney();
                }
                break;
            case R.id.collectingSilver_vipLogin_close:
                collectingSilverVipLoginEdit.setText("");
                collectingSilverVipLoginLinear.setVisibility(View.GONE);
                break;
            case R.id.collectingSilver_vipLogin_linear:
                break;
            case R.id.collectingSilver_vipLogin_scavenging:
                startQrCode();
                break;
            case R.id.collectingSilver_vipLogin_sure:
                if ("".equals(collectingSilverVipLoginEdit.getText().toString().trim())) {
                    Toast.makeText(context, "請先輸入會員賬號", Toast.LENGTH_SHORT).show();
                    return;
                }
//                GetVipInfo();
                break;

            case R.id.collectingSilver_addSku_linear:
                break;
            case R.id.collectingSilver_addSku_off:
                collectingSilverAddSkuEt.setText("");
                collectingSilverAddSkuLinear.setVisibility(View.GONE);
                break;
            case R.id.collectingSilver_addSku_cancel:
                collectingSilverAddSkuEt.setText("");
                collectingSilverAddSkuLinear.setVisibility(View.GONE);
                break;
            case R.id.collectingSilver_addSku_confirm:
                if (TextUtils.isEmpty(collectingSilverAddSkuEt.getText().toString().trim()) || Double.parseDouble(collectingSilverAddSkuEt.getText().toString()) <= 0) {
                    Toast.makeText(context, "必須輸入重量並且大於0", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (Double.parseDouble(collectingSilverAddSkuEt.getText().toString()) > 100) {
                    Toast.makeText(context, "不能大於100KG", Toast.LENGTH_SHORT).show();
                    return;
                }
                collectingSilverAddSkuLinear.setVisibility(View.GONE);
                GoodBean.DataBean.GoodsBean goodBean = classList.get(class_index).getGoods().get(goods_index);
                GoodBean.DataBean.GoodsBean good1 = new GoodBean.DataBean.GoodsBean(goodBean);
                good1.setSku_name(goodBean.getSkujson().get(skuIndex).getSku());
//                good1.setRetail_price(goodBean.getSkujson().get(skuIndex).getRetail_price());
//                good1.setId(goodBean.getId());
//                good1.setC_id(goodBean.getC_id());
//                good1.setGoods_name(goodBean.getGoods_name());
//                good1.setGoods_img(goodBean.getGoods_img());
//                good1.setPricing_method(goodBean.getPricing_method());
                good1.setAgoods_count(Double.parseDouble(collectingSilverAddSkuEt.getText().toString()));
//                good1.setAttribute_state(goodBean.getAttribute_state());
//                good1.setVip_retail_state(goodBean.getVip_retail_state());
//                good1.setStore_mem_status(goodBean.getStore_mem_status());
//                good1.setStore_mem_price(goodBean.getStore_mem_price());
//                good1.setPlus_mem_status(goodBean.getPlus_mem_status());
//                good1.setPlus_price(goodBean.getPlus_price());
//                good1.setPlus_mem_integral(goodBean.getPlus_mem_integral());
//                good1.setStore_mem_integral(goodBean.getStore_mem_integral());
//                good1.setSku_discount(1);
                List<GoodBean.DataBean.GoodsBean.SkuListBean> array1 = new ArrayList<>();
                GoodBean.DataBean.GoodsBean.SkuListBean skuJsonBean1 = new GoodBean.DataBean.GoodsBean.SkuListBean();
                skuJsonBean1.setId(goodBean.getSkujson().get(skuIndex).getId());
                skuJsonBean1.setNum(goodBean.getSkujson().get(skuIndex).getNum());
                skuJsonBean1.setRetail_price(goodBean.getSkujson().get(skuIndex).getRetail_price());
                skuJsonBean1.setSku(goodBean.getSkujson().get(skuIndex).getSku());
                skuJsonBean1.setSku_res(goodBean.getSkujson().get(skuIndex).getSku_res());
                skuJsonBean1.setSku_code(goodBean.getSkujson().get(skuIndex).getSku_code());
                skuJsonBean1.setStore_mem_status(goodBean.getSkujson().get(skuIndex).getStore_mem_status());
                skuJsonBean1.setStore_mem_price(goodBean.getSkujson().get(skuIndex).getStore_mem_price());
                skuJsonBean1.setPlus_price(goodBean.getSkujson().get(skuIndex).getPlus_price());
                skuJsonBean1.setPlus_mem_integral(goodBean.getSkujson().get(skuIndex).getPlus_mem_integral());
                skuJsonBean1.setStore_mem_integral(goodBean.getSkujson().get(skuIndex).getStore_mem_integral());
                array1.add(skuJsonBean1);
                good1.setSkujson(array1);
                if ("1".equals(good1.getSerial_number_state())) {
                    boolean have = false;
                    for (int i = 0; i < selectList.size(); i++) {
                        if (good1.getId().equals(selectList.get(i).getId()) &&
                                good1.getIs_gift_good() == selectList.get(i).getIs_gift_good()) {
                            have = true;
                            break;
                        }
                    }
                    if (!have) {
//                        good1.setAgoods_count((double) 0);
//                        selectList.add(good1);
//                        Toast.makeText(context, "添加成功", Toast.LENGTH_SHORT).show();

                        intent = new Intent(context, StringCodeOperationActivity.class);
                        intent.putExtra("good", selectList.get(selectList.size() - 1));
                        intent.putExtra("operation", 1);
                        startActivityForResult(intent, 300);
                    }
                } else {
                    selectList.add(good1);
                    allNum = allNum + 1;
                }
                countMoney();
                break;
            case R.id.tv_confirm: //規格商品確定
                skuSubmit();
                break;
            case R.id.ll_sku:
                llSku.setVisibility(View.GONE);
                break;
            case R.id.collectingSilver_noCode:
                collectingSilverNoCodeLinear.setVisibility(View.VISIBLE);
                break;
            /**商品條碼及貨號查詢*/
            case R.id.collectingSilver_search:
                if (TextUtils.isEmpty(collectingSilverSearchEt.getText().toString().trim())) {
                    Toast.makeText(context, "請輸入數據", Toast.LENGTH_SHORT).show();
                } else {
                    selectGoods(collectingSilverSearchEt.getText().toString().trim());
                }
                break;
            case R.id.iv_collectingSilver_underline:
                collectingSilverSearchEt.setText("");
                break;
            case R.id.tv_collectingSilver_underline_cancel:
                collectingSilverSearchEt.setText("");
                break;
            case R.id.tv_collectingSilver_underline_confirm:
                if (TextUtils.isEmpty(collectingSilverSearchEt.getText().toString().trim())) {
                    Toast.makeText(context, "請輸入數據", Toast.LENGTH_SHORT).show();
                } else {
                    selectGoods(collectingSilverSearchEt.getText().toString().trim());
                }
                break;
            case R.id.ll_collectingSilver_underline:
                break;
            case R.id.collectingSilver_noCode_linear:
                break;
            case R.id.close_choose:
                llSku.setVisibility(View.GONE);
                break;
            case R.id.collectingSilver_noCode_cancel:
                collectingSilverNoCodePrice.setText("");
                collectingSilverNoCodeKg.setText("");
                collectingSilverNoCodeNoWeight.setChecked(true);
                collectingSilverNoCodeWeight.setChecked(false);
                collectingSilverNoCodeLinear.setVisibility(View.GONE);
                break;
            case R.id.collectingSilver_noCode_sure:
                if ("".equals(collectingSilverNoCodePrice.getText().toString().trim()) || !Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$").matcher(collectingSilverNoCodePrice.getText().toString().trim()).matches() || Double.parseDouble(collectingSilverNoCodePrice.getText().toString()) <= 0) {
                    Toast.makeText(context, "請輸入正確的價格", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (collectingSilverNoCodeNoWeight.isChecked()) {
                    GoodBean.DataBean.GoodsBean wumaBean = new GoodBean.DataBean.GoodsBean();
                    wumaBean.setId("0");
                    wumaBean.setRetail_price(collectingSilverNoCodePrice.getText().toString().trim());
                    wumaBean.setGoods_name("無碼商品");
                    wumaBean.setGoods_img("0");
                    wumaBean.setPricing_method("1");
                    wumaBean.setAttribute_state("0");
                    wumaBean.setAgoods_count(1.0);
                    wumaBean.setSku_discount(1);
                    wumaBean.setStore_mem_price(collectingSilverNoCodePrice.getText().toString().trim());
                    wumaBean.setPlus_price(collectingSilverNoCodePrice.getText().toString().trim());
                    wumaBean.setPurch_price(collectingSilverNoCodePrice.getText().toString().trim());
                    wumaBean.setTemporaryPrice(collectingSilverNoCodePrice.getText().toString().trim());
                    wumaBean.setVip_retail_state("0");
                    wumaBean.setCompany(collectingSilverNoCodeCompany.getText().toString().trim());
                    selectList.add(wumaBean);
                    collectingSilverNoCodeLinear.setVisibility(View.GONE);
                    countMoney();
                } else {
                    if ("".equals(collectingSilverNoCodeKg.getText().toString()) || Double.parseDouble(collectingSilverNoCodeKg.getText().toString()) == 0) {
                        Toast.makeText(context, "請輸入正確的數量", Toast.LENGTH_SHORT).show();
                        return;
                    }
                    GoodBean.DataBean.GoodsBean noCodeBean = new GoodBean.DataBean.GoodsBean();
                    noCodeBean.setId("0");
                    noCodeBean.setRetail_price(collectingSilverNoCodePrice.getText().toString().trim());
                    noCodeBean.setGoods_name("無碼商品");
                    noCodeBean.setGoods_img("0");
                    noCodeBean.setPricing_method("2");
                    noCodeBean.setAttribute_state("0");
                    noCodeBean.setSku_discount(1);
                    noCodeBean.setStore_mem_price(collectingSilverNoCodePrice.getText().toString().trim());
                    noCodeBean.setPlus_price(collectingSilverNoCodePrice.getText().toString().trim());
                    noCodeBean.setAgoods_count(Double.parseDouble(collectingSilverNoCodeKg.getText().toString()));
                    noCodeBean.setPurch_price(collectingSilverNoCodePrice.getText().toString().trim());
                    noCodeBean.setTemporaryPrice(collectingSilverNoCodePrice.getText().toString().trim());
                    noCodeBean.setVip_retail_state("0");
                    noCodeBean.setCompany(unitList.get(unitIndex));
                    selectList.add(noCodeBean);
                    collectingSilverNoCodeLinear.setVisibility(View.GONE);
                }
                collectingSilverNoCodePrice.setText("");
                collectingSilverNoCodeKg.setText("");
                collectingSilverNoCodeNoWeight.setChecked(true);
                collectingSilverNoCodeWeight.setChecked(false);
                collectingSilverNoCodeSpinnerCompany.setVisibility(View.GONE);
                collectingSilverNoCodeCompany.setVisibility(View.VISIBLE);
                collectingSilverNoCodeCompany.setText("");
                collectingSilverNoCodeSpinnerCompany.setSelection(0);
                unitIndex = 0;
                countMoney();
                setGoodsAdapter();
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                // 強制隱藏軟鍵盤
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                break;
            case R.id.collectingSilver_noCode_off:
                collectingSilverNoCodePrice.setText("");
                collectingSilverNoCodeKg.setText("");
                collectingSilverNoCodeNoWeight.setChecked(true);
                collectingSilverNoCodeWeight.setChecked(false);
                collectingSilverNoCodeLinear.setVisibility(View.GONE);
                break;
            case R.id.title_back://返回按鈕
                finish();
                break;
            case R.id.collectingSilver_scavenging://掃碼
                startQrCode();
                break;
            case R.id.collectingSilver_settlement://結算
                if (selectList.size() == 0) {
                    Toast.makeText(context, "沒有選擇商品", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (allNum - giftGoodsNum == 0) {
                    Toast.makeText(context, "請選擇商品", Toast.LENGTH_SHORT).show();
                    return;
                }
                llSku.setVisibility(View.GONE);
                collectingSilverSelectedLinear.setVisibility(View.GONE);
                if ("0".equals(aCache.getAsString("placeAnOrder"))) {
                    Toast.makeText(context, "商品單品折扣設置錯誤，請重新設置", Toast.LENGTH_SHORT).show();
                    return;
                }
                placeOrder();
                break;
            case R.id.collectingSilver_shopCar://購物車按鈕
                llSku.setVisibility(View.GONE);
                if (collectingSilverSelectedLinear.getVisibility() == View.GONE && selectList.size() > 0) {
                    setSelectedAdapter();
                    collectingSilverSelectedLinear.setVisibility(View.VISIBLE);
                } else if (collectingSilverSelectedLinear.getVisibility() == View.GONE && selectList.size() == 0) {
                    Toast.makeText(context, "沒有選擇商品", Toast.LENGTH_SHORT).show();
                } else {
                    collectingSilverSelectedLinear.setVisibility(View.GONE);
                }
                break;
            case R.id.collectingSilver_empty://購物車清空按鈕
                for (int i = 0; i < classList.size(); i++) {
                    for (int s = 0; s < classList.get(i).getGoods().size(); s++) {
                        classList.get(i).getGoods().get(s).setAgoods_count(null);
                        classList.get(i).getGoods().get(s).setSku_discount(1);
                        classList.get(i).getGoods().get(s).setSerialList(new ArrayList<>());
                    }
                }
                giftGoodsNum = 0;
                mGiftGoodsNumMap.clear();
                selectList.clear();
                countMoney();
                setGoodsAdapter();
                setSelectedAdapter();
                collectingSilverSelectedLinear.setVisibility(View.GONE);
                break;
            case R.id.collectingSilver_selected_linear://購物車界面
                collectingSilverSelectedLinear.setVisibility(View.GONE);
                break;
            case R.id.collectingSilver_weigh_sure://稱重確定按鈕

                if (Double.parseDouble(collectingSilverWeighNum.getText().toString()) == 0) {
                    return;
                }
                chooseGoodBean.setAgoods_count(Double.parseDouble(collectingSilverWeighNum.getText().toString()));
                selectList.add(chooseGoodBean);
                allNum = allNum + 1;
                allPrice = allPrice + (Double.parseDouble(chooseGoodBean.getRetail_price()) * Double.parseDouble(collectingSilverWeighNum.getText().toString()));

                collectingSilverWeighLinear.setVisibility(View.GONE);
                if (!TextUtils.isEmpty(collectingSilverSearchEt.getText().toString())) {
                    collectingSilverSearchEt.setText("");
                }
                setSelectedAdapter();
                countMoney();

                break;
            case R.id.collectingSilver_weigh_linear:
                collectingSilverWeighLinear.setVisibility(View.GONE);
                break;
        }
    }

    private void skuSubmit(){
        if(mSkuEditView.getVisibility()==View.VISIBLE){
            String v=mSkuEditView.getEditableText().toString();
            if(v.isEmpty()){
                Toast.makeText(context, "請輸入商品數量", Toast.LENGTH_SHORT).show();
                return;
            }
        }
        //here
        if (sku_index == 9999) {
            Toast.makeText(context, "當前規格沒有商品，請選擇其它規格", Toast.LENGTH_SHORT).show();
            return;
        }
        GoodBean.DataBean.GoodsBean current=mUpdateItem;
        if(current==null){
            current=classList.get(class_index).getGoods().get(goods_index);
        }
        if (isSearchGoods) {
            if (mMap == null || mMap.size() == 0 || mMap.size() != current.getSkuinfo().size()) {
                Toast.makeText(context, "請選擇規格", Toast.LENGTH_SHORT).show();
                return;
            } else {
                String paths = "";
                for (int i = mMap.size() - 1; i >= 0; i--) {
                    paths = mMap.get(i) + "," + paths;
                }
                paths = paths.substring(0, paths.length() - 1);
                boolean have = false;
                int index = 0;
                int path_index = 0;
//                   if (!isSearchGoods){
//                       for (int i = 0; i < goodList.get(goods_index).getSkujson().size(); i++) {
//                           if (paths.equals(goodList.get(goods_index).getSkujson().get(i).getSku_res())) {
//                               path_index = i;
//                               for (int s = 0; s < selectList.size(); s++) {
//                                   if (selectList.get(s).getSkujson() != null && selectList.get(s).getSkujson().size() > 0) {
//                                       if (paths.equals(selectList.get(s).getSkujson().get(0).getSku_res()) &&
//                                               goodList.get(goods_index).getId() == selectList.get(s).getId()) {
//                                           have = true;
//                                           index = s;
//                                           break;
//                                       }
//                                   }
//                               }
//                           }
//                       }
//                   }else {
                for (int i = 0; i < current.getSkujson().size(); i++) {
                    if (paths.equals(current.getSkujson().get(i).getSku_res())) {
                        path_index = i;
                        for (int s = 0; s < selectList.size(); s++) {
                            if (selectList.get(s).getSkujson() != null && selectList.get(s).getSkujson().size() > 0) {
                                if (paths.equals(selectList.get(s).getSkujson().get(0).getSku_res())
                                        && Objects.equals(current.getId(), selectList.get(s).getId())) {
                                    have = true;
                                    index = s;
                                    break;
                                }
                            }
                        }
                    }
                }
//                   }
                Log.e(TAG, "onViewClicked: item="+mUpdateItem);

                if(mUpdateItem!=null){
                    GoodBean.DataBean.GoodsBean goodsBean = new GoodBean.DataBean.GoodsBean(current);
//                        Log.e(TAG, "onViewClicked: goodList.get(index).getSerial_number_state()========"+goodList.get(index).getSerial_number_state() );
                    if ("1".equals(goodsBean.getSerial_number_state())) {
                        goodsBean.setAgoods_count((double) 0);
                    } else {
                        goodsBean.setAgoods_count((double) 1);
                    }
                    goodsBean.setRetail_price(goodsBean.getSkujson().get(path_index).getRetail_price());
                    goodsBean.setSku_discount(1);
                    goodsBean.setSku_name(goodsBean.getSkujson().get(path_index).getSku());
                    List<GoodBean.DataBean.GoodsBean.SkuListBean> array = new ArrayList<>();
                    GoodBean.DataBean.GoodsBean.SkuListBean skujsonBean = new GoodBean.DataBean.GoodsBean.SkuListBean();
                    skujsonBean.setId(goodsBean.getSkujson().get(path_index).getId());
                    skujsonBean.setNum(goodsBean.getSkujson().get(path_index).getNum());
                    skujsonBean.setSku_goods_number(goodsBean.getSkujson().get(path_index).getSku_goods_number());
                    skujsonBean.setSku_code(goodsBean.getSkujson().get(path_index).getSku_code());
                    skujsonBean.setRetail_price(goodsBean.getSkujson().get(path_index).getRetail_price());
                    skujsonBean.setSku(goodsBean.getSkujson().get(path_index).getSku());
                    skujsonBean.setSku_res(goodsBean.getSkujson().get(path_index).getSku_res());
                    skujsonBean.setStore_mem_status(goodsBean.getSkujson().get(path_index).getStore_mem_status());
                    skujsonBean.setStore_mem_price(goodsBean.getSkujson().get(path_index).getStore_mem_price());
                    skujsonBean.setPlus_price(goodsBean.getSkujson().get(path_index).getPlus_price());
                    skujsonBean.setPlus_mem_integral(goodsBean.getSkujson().get(path_index).getPlus_mem_integral());
                    skujsonBean.setStore_mem_integral(goodsBean.getSkujson().get(path_index).getStore_mem_integral());
                    array.add(skujsonBean);
                    goodsBean.setSkujson(array);
                    if(!isSkuSubmit(mUpdateItem,false)){
                        return;
                    }
                    int addCount=Integer.parseInt(mSkuEditView.getEditableText().toString());

                    for (int i = 0; i < selectList.size(); i++) {
                        if(Objects.equals(selectList.get(i).getId(), mUpdateItem.getId())){
                            selectList.get(i).setRetail_price(goodsBean.getSkujson().get(path_index).getRetail_price());
                            selectList.get(i).setSku_discount(mUpdateItem.getSku_discount());
                            selectList.get(i).setSku_name(goodsBean.getSkujson().get(path_index).getSku());
                            selectList.get(i).setSku_name(goodsBean.getSkujson().get(path_index).getSku());
                            selectList.get(i).setAgoods_count((double) addCount);
                            if ("1".equals(goodsBean.getSerial_number_state())) {
                                selectList.get(i).setAgoods_count((double) 0);
                            }else {
                                for (int i1 = 0; i1 < goodList.size(); i1++) {
                                    if(goodList.get(i1).getId().equals(selectList.get(i).getId())){
                                        goodList.get(i1).setAgoods_count(selectList.get(i).getAgoods_count());
                                        setNumber(goodList.get(i1));
                                    }
                                }
                            }
                            selectList.get(i).setSkujson(array);
                        }
                    }
                    setSelectedAdapter();
                    countMoney();
                    llSku.setVisibility(View.GONE);
                    return;
                }
                if (have) {
                    int addCount=Integer.parseInt(mSkuEditView.getEditableText().toString());
                    if (!"1".equals(current.getSerial_number_state())) {
                        if(!isSkuSubmit(selectList.get(index),false)){
                            return;
                        }
                        selectList.get(index).setAgoods_count(selectList.get(index).getAgoods_count() == null ? 0.0 : selectList.get(index).getAgoods_count() + 1);
                        selectList.get(index).setAgoods_count((double) addCount);
                        setNumber(selectList.get(index));
                    }
                    setSelectedAdapter();
                    countMoney();
                    llSku.setVisibility(View.GONE);
                } else {
                    GoodBean.DataBean.GoodsBean goodsBean = new GoodBean.DataBean.GoodsBean(current);
//                        Log.e(TAG, "onViewClicked: goodList.get(index).getSerial_number_state()========"+goodList.get(index).getSerial_number_state() );
                    if ("1".equals(goodsBean.getSerial_number_state())) {
                        goodsBean.setAgoods_count((double) 0);
                    } else {
                        int addCount=Integer.parseInt(mSkuEditView.getEditableText().toString());
                        if(!isSkuSubmit(selectList.get(index),false)){
                            return;
                        }
                        goodsBean.setAgoods_count((double) addCount);
                        setNumber(selectList.get(index));
                    }
                    goodsBean.setRetail_price(goodsBean.getSkujson().get(path_index).getRetail_price());
                    goodsBean.setSku_discount(1);
                    goodsBean.setSku_name(goodsBean.getSkujson().get(path_index).getSku());
                    List<GoodBean.DataBean.GoodsBean.SkuListBean> array = new ArrayList<>();
                    GoodBean.DataBean.GoodsBean.SkuListBean skujsonBean = new GoodBean.DataBean.GoodsBean.SkuListBean();
                    skujsonBean.setId(goodsBean.getSkujson().get(path_index).getId());
                    skujsonBean.setNum(goodsBean.getSkujson().get(path_index).getNum());
                    skujsonBean.setSku_goods_number(goodsBean.getSkujson().get(path_index).getSku_goods_number());
                    skujsonBean.setSku_code(goodsBean.getSkujson().get(path_index).getSku_code());
                    skujsonBean.setRetail_price(goodsBean.getSkujson().get(path_index).getRetail_price());
                    skujsonBean.setSku(goodsBean.getSkujson().get(path_index).getSku());
                    skujsonBean.setSku_res(goodsBean.getSkujson().get(path_index).getSku_res());
                    skujsonBean.setStore_mem_status(goodsBean.getSkujson().get(path_index).getStore_mem_status());
                    skujsonBean.setStore_mem_price(goodsBean.getSkujson().get(path_index).getStore_mem_price());
                    skujsonBean.setPlus_price(goodsBean.getSkujson().get(path_index).getPlus_price());
                    skujsonBean.setPlus_mem_integral(goodsBean.getSkujson().get(path_index).getPlus_mem_integral());
                    skujsonBean.setStore_mem_integral(goodsBean.getSkujson().get(path_index).getStore_mem_integral());
                    array.add(skujsonBean);
                    goodsBean.setSkujson(array);
//                        Log.e(TAG, "onViewClicked: 添加的規格商品的數量是======="+goodsBean.getAgoods_count() );
                    Toast.makeText(context, "添加成功", Toast.LENGTH_SHORT).show();
                    if ("1".equals(goodsBean.getSerial_number_state())) {
                        boolean have1 = false;
                        int indexs = -1;

                        for (int s = 0; s < selectList.size(); s++) {
                            if (goodsBean.getId().equals(selectList.get(s).getId()) &&
                                    goodsBean.getIs_gift_good() == selectList.get(s).getIs_gift_good()) {
                                for (int i = 0; i < selectList.get(s).getSkuList().size(); i++) {
                                    if (goodsBean.getSkuList().get(0).getId().equals(selectList.get(s).getSkuList().get(i).getId())) {
                                        have1 = true;
                                        indexs = s;
                                        break;
                                    }
                                }
                            }
                        }
                        if (have1) {
//                                selectList.add(goodsBean);
//                                Toast.makeText(context, "添加成功", Toast.LENGTH_SHORT).show();

                            intent = new Intent(context, StringCodeOperationActivity.class);
                            intent.putExtra("good", selectList.get(indexs));
                            intent.putExtra("operation", 1);
                            startActivityForResult(intent, 300);
                        } else {
                            intent = new Intent(context, StringCodeOperationActivity.class);
                            intent.putExtra("good", goodsBean);
                            intent.putExtra("operation", 1);
                            startActivityForResult(intent, 300);
                        }
                    } else {
                        selectList.add(goodsBean);
                    }
                    setSelectedAdapter();
                    countMoney();
                    llSku.setVisibility(View.GONE);
                }
            }
        } else {
            if (mMap == null || mMap.size() == 0 || mMap.size() != current.getSkuinfo().size()) {
                Toast.makeText(context, "請選擇規格", Toast.LENGTH_SHORT).show();
                return;
            } else {
                String paths = "";
                for (int i = mMap.size() - 1; i >= 0; i--) {
                    paths = mMap.get(i) + "," + paths;
                }
                paths = paths.substring(0, paths.length() - 1);
                boolean have = false;
                int index = 0;
                int path_index = 0;
//                   if (!isSearchGoods){
                for (int i = 0; i < current.getSkujson().size(); i++) {
                    if (paths.equals(current.getSkujson().get(i).getSku_res())) {
                        path_index = i;
                        for (int s = 0; s < selectList.size(); s++) {
                            if (selectList.get(s).getSkujson() != null && selectList.get(s).getSkujson().size() > 0) {
                                if (paths.equals(selectList.get(s).getSkujson().get(0).getSku_res()) && Objects.equals(current.getId(), selectList.get(s).getId())) {
                                    have = true;
                                    index = s;
                                    break;
                                }
                            }
                        }
                    }
                }
//                   }else {
//                            for (int i = 0; i < classList.get(class_index).getGoods().get(goods_index).getSkujson().size(); i++) {
//                                if (paths.equals(classList.get(class_index).getGoods().get(goods_index).getSkujson().get(i).getSku_res())) {
//                                    path_index = i;
//                                    for (int s = 0; s < selectList.size(); s++) {
//                                        if (selectList.get(s).getSkujson() != null && selectList.get(s).getSkujson().size() > 0) {
//                                            if (paths.equals(selectList.get(s).getSkujson().get(0).getSku_res()) &&
//                                                    classList.get(class_index).getGoods().get(goods_index).getId() == selectList.get(s).getId()) {
//                                                have = true;
//                                                index = s;
//                                                break;
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                   }
                int addCount=Integer.parseInt(mSkuEditView.getEditableText().toString());
                if(mUpdateItem!=null){
                    GoodBean.DataBean.GoodsBean goodsBean = new GoodBean.DataBean.GoodsBean(current);
//                        Log.e(TAG, "onViewClicked: goodList.get(index).getSerial_number_state()========"+goodList.get(index).getSerial_number_state() );
                    if(!isSkuSubmit(mUpdateItem,false)){
                        return;
                    }
                    goodsBean.setAgoods_count((double) addCount);
                    goodsBean.setRetail_price(goodsBean.getSkujson().get(path_index).getRetail_price());
                    goodsBean.setSku_discount(1);
                    goodsBean.setSku_name(goodsBean.getSkujson().get(path_index).getSku());
                    List<GoodBean.DataBean.GoodsBean.SkuListBean> array = new ArrayList<>();
                    GoodBean.DataBean.GoodsBean.SkuListBean skujsonBean = new GoodBean.DataBean.GoodsBean.SkuListBean();
                    skujsonBean.setId(goodsBean.getSkujson().get(path_index).getId());
                    skujsonBean.setNum(goodsBean.getSkujson().get(path_index).getNum());
                    skujsonBean.setRetail_price(goodsBean.getSkujson().get(path_index).getRetail_price());
                    skujsonBean.setSku_goods_number(goodsBean.getSkujson().get(path_index).getSku_goods_number());
                    skujsonBean.setSku_code(goodsBean.getSkujson().get(path_index).getSku_code());
                    skujsonBean.setSku(goodsBean.getSkujson().get(path_index).getSku());
                    skujsonBean.setSku_res(goodsBean.getSkujson().get(path_index).getSku_res());
                    skujsonBean.setStore_mem_status(goodsBean.getSkujson().get(path_index).getStore_mem_status());
                    skujsonBean.setStore_mem_price(goodsBean.getSkujson().get(path_index).getStore_mem_price());
                    skujsonBean.setPlus_price(goodsBean.getSkujson().get(path_index).getPlus_price());
                    skujsonBean.setPlus_mem_integral(goodsBean.getSkujson().get(path_index).getPlus_mem_integral());
                    skujsonBean.setStore_mem_integral(goodsBean.getSkujson().get(path_index).getStore_mem_integral());
                    array.add(skujsonBean);
                    goodsBean.setSkujson(array);

                    for (int i = 0; i < selectList.size(); i++) {
                        if(Objects.equals(selectList.get(i).getId(), mUpdateItem.getId())){
                            selectList.get(i).setRetail_price(goodsBean.getRetail_price());
                            selectList.get(i).setSku_discount(mUpdateItem.getSku_discount());
                            selectList.get(i).setAgoods_count((double) addCount);
                            selectList.get(i).setSku_name(goodsBean.getSku_name());
                            selectList.get(i).setSkujson(goodsBean.getSkujson());
                            setNumber(selectList.get(i));
                        }
                    }
                    setSelectedAdapter();
                    countMoney();
                    llSku.setVisibility(View.GONE);
                    return;
                }
                if (have) {
                    if (!"1".equals(goodList.get(index).getSerial_number_state())) {
                        selectList.get(index).setAgoods_count(selectList.get(index).getAgoods_count() == null ? 0.0 : selectList.get(index).getAgoods_count() + 1);
                        if(!isSkuSubmit(selectList.get(index),false)){
                            return;
                        }
                        selectList.get(index).setAgoods_count((double) addCount);
                        setNumber(selectList.get(index));
                    }
                    setSelectedAdapter();
                    countMoney();
                    llSku.setVisibility(View.GONE);
                } else {
                    GoodBean.DataBean.GoodsBean goodsBean = new GoodBean.DataBean.GoodsBean(current);
//                        Log.e(TAG, "onViewClicked: goodList.get(index).getSerial_number_state()========"+goodList.get(index).getSerial_number_state() );
                    if ("1".equals(goodsBean.getSerial_number_state())) {
                        goodsBean.setAgoods_count((double) 0);
                    } else {
                        goodsBean.setAgoods_count((double) 1);
                    }
                    goodsBean.setRetail_price(goodsBean.getSkujson().get(path_index).getRetail_price());
                    goodsBean.setSku_discount(1);
                    goodsBean.setSku_name(goodsBean.getSkujson().get(path_index).getSku());
                    List<GoodBean.DataBean.GoodsBean.SkuListBean> array = new ArrayList<>();
                    GoodBean.DataBean.GoodsBean.SkuListBean skujsonBean = new GoodBean.DataBean.GoodsBean.SkuListBean();
                    skujsonBean.setId(goodsBean.getSkujson().get(path_index).getId());
                    skujsonBean.setNum(goodsBean.getSkujson().get(path_index).getNum());
                    skujsonBean.setRetail_price(goodsBean.getSkujson().get(path_index).getRetail_price());
                    skujsonBean.setSku_goods_number(goodsBean.getSkujson().get(path_index).getSku_goods_number());
                    skujsonBean.setSku_code(goodsBean.getSkujson().get(path_index).getSku_code());
                    skujsonBean.setSku(goodsBean.getSkujson().get(path_index).getSku());
                    skujsonBean.setSku_res(goodsBean.getSkujson().get(path_index).getSku_res());
                    skujsonBean.setStore_mem_status(goodsBean.getSkujson().get(path_index).getStore_mem_status());
                    skujsonBean.setStore_mem_price(goodsBean.getSkujson().get(path_index).getStore_mem_price());
                    skujsonBean.setPlus_price(goodsBean.getSkujson().get(path_index).getPlus_price());
                    skujsonBean.setPlus_mem_integral(goodsBean.getSkujson().get(path_index).getPlus_mem_integral());
                    skujsonBean.setStore_mem_integral(goodsBean.getSkujson().get(path_index).getStore_mem_integral());
                    array.add(skujsonBean);
                    if(!isSkuSubmit(goodsBean,false)){
                        return;
                    }
                    if ("1".equals(goodsBean.getSerial_number_state())) {
                        goodsBean.setAgoods_count((double) 0);
                    } else {
                        goodsBean.setAgoods_count((double) addCount);
                    }
                    goodsBean.setSkujson(array);
                    setNumber(goodsBean);
//                        Log.e(TAG, "onViewClicked: 添加的規格商品的數量是======="+goodsBean.getAgoods_count() );
                    Toast.makeText(context, "添加成功", Toast.LENGTH_SHORT).show();
                    if ("1".equals(goodsBean.getSerial_number_state())) {
                        boolean have1 = false;
                        int indexs = -1;

                        for (int s = 0; s < selectList.size(); s++) {
                            if (goodsBean.getId().equals(selectList.get(s).getId()) &&
                                    goodsBean.getIs_gift_good() == selectList.get(s).getIs_gift_good()) {
                                for (int i = 0; i < selectList.get(s).getSkuList().size(); i++) {
                                    if (goodsBean.getSkuList().get(0).getId().equals(selectList.get(s).getSkuList().get(i).getId())) {
                                        have1 = true;
                                        indexs = s;
                                        break;
                                    }
                                }
                            }
                        }
                        if (have1) {
//                                selectList.add(goodsBean);
//                                Toast.makeText(context, "添加成功", Toast.LENGTH_SHORT).show();

                            intent = new Intent(context, StringCodeOperationActivity.class);
                            intent.putExtra("good", selectList.get(indexs));
                            intent.putExtra("operation", 1);
                            startActivityForResult(intent, 300);
                        } else {
                            intent = new Intent(context, StringCodeOperationActivity.class);
                            intent.putExtra("good", goodsBean);
                            intent.putExtra("operation", 1);
                            startActivityForResult(intent, 300);
                        }
                    } else {
                        selectList.add(goodsBean);
                    }
                    setSelectedAdapter();
                    countMoney();
                    llSku.setVisibility(View.GONE);
                }
            }
        }
    }
    private void setNumber(GoodBean.DataBean.GoodsBean item){
        setNumber(item,0);
    }
    private void setNumber(GoodBean.DataBean.GoodsBean item,int setCount){
        int index=0;
        for (int i = 0; i < goodList.size(); i++) {
            if(goodList.get(i).getId().equals(item.getId())){
                index=i;
            }
        }
        int addCount=setCount;
        if(setCount<=0){
            addCount=Integer.parseInt(mSkuEditView.getEditableText().toString());
        }
        if(addCount!=item.getAgoods_count()){
            return;
        }
        if ("1".equals(goodList.get(index).getSerial_number_state())) {
            return;
        }else if (!"".equals(goodList.get(index).getCheng_price())){
            return;
        }
        int gift_good=0;
        if(mUpdateItem!=null){
            gift_good=mUpdateItem.getIs_gift_good();
        }else{
            gift_good=goodList.get(index).getIs_gift_good();
        }
        if (gift_good == 1) {
            if(addCount>item.getAgoods_count()){
                giftGoodsNum+=addCount-item.getAgoods_count();
            }else {
                giftGoodsNum-=item.getAgoods_count()-addCount;
                if(giftGoodsNum<=0){
                    giftGoodsNum=0;
                }
            }
        }
    }
    private boolean isSkuSubmit(GoodBean.DataBean.GoodsBean item,boolean add){
        return isSkuSubmit(item,add,0);
    }
    private boolean isSkuSubmit(GoodBean.DataBean.GoodsBean item,boolean add,int setCount){
        int index=0;
        for (int i = 0; i < goodList.size(); i++) {
            if(goodList.get(i).getId().equals(item.getId())){
                index=i;
            }
        }
        int addCount=setCount;
        if(setCount<=0){
            addCount=Integer.parseInt(mSkuEditView.getEditableText().toString());
        }
        if(addCount<=item.getAgoods_count()){
            return true;
        }
        int count=0;
        for (GoodBean.DataBean.GoodsBean goodsBean : selectList) {
            if(goodsBean.getId().equals(item.getId())){
            }else {
                count+=goodsBean.getAgoods_count();
            }
        }
        if ("1".equals(goodList.get(index).getSerial_number_state())) {
            Toast.makeText(context, "串碼商品無法修改數量", Toast.LENGTH_SHORT).show();
            return false;
        }else if (!"".equals(goodList.get(index).getCheng_price())){
            Toast.makeText(context, "條碼商品無法修改數量", Toast.LENGTH_SHORT).show();
            return false;
        }
        int gift_good=0;
        if(mUpdateItem!=null){
            gift_good=mUpdateItem.getIs_gift_good();
        }else{
            gift_good=goodList.get(index).getIs_gift_good();
        }
        if (gift_good == 1) {
            if (addCount >= Integer.parseInt(aCache.getAsString("goods_gifts_num"))) {
                if(add){
                    Toast.makeText(context, "不能繼續增加了", Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(context, "商品數量已超出該商品庫存", Toast.LENGTH_SHORT).show();
                }
                return false;
            }
        }
        String pricing_method="";
        for (int i = 0; i < selectList.size(); i++) {
            if(selectList.get(i).getId().equals(goodList.get(index).getId())){
                pricing_method=selectList.get(i).getPricing_method();
            }
        }
        if(pricing_method.isEmpty()){
            pricing_method=goodList.get(index).getPricing_method();
        }
        if ("1".equals(pricing_method)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 判斷是否點擊回車事件
     */
    private boolean getBoolean(int actionId, KeyEvent event) {
        boolean e = actionId == EditorInfo.IME_ACTION_SEND
                || actionId == EditorInfo.IME_ACTION_DONE
                || (event != null && KeyEvent.KEYCODE_ENTER == event.getKeyCode() && KeyEvent.ACTION_DOWN == event.getAction());
        return e;
    }

    @Subscribe
    public void onEventMainThread(NFCBean event) {
        Log.e(TAG, "onEventMainThread: " + event.getType());
        if (event.getVipId() == 9999) {
            giftGoodsNum = 0;
            mGiftGoodsNumMap.clear();
            isVip = 0;
            infoBean = null;
//            vipinfoBean = null;
            vipDiscount = "";
//            collectingSilverVipLogin.setText("會員");
            gifts.clear();
            class_index = 0;
            selectList.clear();
            setSelectedAdapter();
            classificationAdapter.setSelect(0);
            goodList.clear();
            for (int i = 0; i < classList.size(); i++) {
                for (int s = 0; s < classList.get(i).getGoods().size(); s++) {
                    classList.get(i).getGoods().get(s).setAgoods_count(1.0);
                    classList.get(i).getGoods().get(s).setSku_discount(1);

                    classList.get(i).getGoods().get(s).setGift_id("");
                    classList.get(i).getGoods().get(s).setIs_gift_good(0);

                    classList.get(i).getGoods().get(s).setSerialList(new ArrayList<>());
                    if (i == 0) {
                        goodList.add(classList.get(i).getGoods().get(s));
                    }
                }
            }
            setGoodsAdapter();
            countMoney();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.e(TAG, "onResume: classList.size=" + classList.size());
        if (classList.size() == 0) {
            GetGoodList("0");
        }
        if (mNfcAdapter != null && isSupportNfc && isOpenNfc) {
            mNfcAdapter.enableForegroundDispatch(this, pi, null, null);
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        String ex_id;
        Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        String num1 = ByteArrayToHexString(tagFromIntent.getId());
        String num2 = flipHexStr(num1);
        Log.e(TAG, "onNewIntent: 1=" + num2);
        String num = "";
        if (num2.length() > 10) {
            try {
                num = ByteArrayTohexHepler.hex2String(num2);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            Long cardNo = Long.parseLong(num2, 16);
            Log.e(TAG, "onNewIntent: 2=" + cardNo);
            num = cardNo.toString();
        }
        if (num.length() != 10) {
            while (num.length() < 10) {
                num = "0" + num;
            }
        }
        ex_id = num;
        Log.e("==================", ex_id);
        //Toast.makeText(getApplicationContext(), num, Toast.LENGTH_SHORT).show();
        if (collectingSilverVipLoginLinear.getVisibility() == View.VISIBLE) {
            collectingSilverVipLoginEdit.setText(ex_id);
            collectingSilverVipLoginEdit.setSelection(ex_id.length());
        }
    }

    // 開始掃碼
    private void startQrCode() {
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            // 申請權限
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, Constant.REQ_PERM_CAMERA);
            return;
        }
        LogUtil.i(TAG, "--------------------> ");


        // 二維碼掃碼
        //Intent intent = new Intent(context, CaptureActivity.class);
        //startActivityForResult(intent, Constant.REQ_QR_CODE);
        Intent intent = new Intent(context, InfraredScanActivity.class);
        startActivityForResult(intent, Constant.REQ_QR_CODE);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                           @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case Constant.REQ_PERM_CAMERA:
                // 攝像頭權限申請
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // 獲得授權
                    startQrCode();
                } else {
                    // 被禁止授權
                    Toast.makeText(context, "請至權限中心打開本應用的相機訪問權限", Toast.LENGTH_LONG).show();
                }
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        LogUtil.i(TAG, "onActivityResult --------------------> (data != null) :" + (data != null) + ", requestCode:" + requestCode + " ,resultCode:" + resultCode);
        if (data != null) {
            Bundle bundle = data.getExtras();
            switch (requestCode) {
                case Constant.REQ_QR_CODE:
                    String scan_msg = bundle.getString(Constant.INTENT_EXTRA_KEY_QR_SCAN);
                    if (scan_msg == null || scan_msg.isEmpty()) {
                        if (resultCode == RESULT_CANCELED) {
                            String extData = MemoryCacheManager.getInstance().getScanData();
                            if (extData != null && !extData.isEmpty()) {
                                scan_msg = extData;
                            }
                        }
                    }
                    if (collectingSilverVipLoginLinear.getVisibility() == View.VISIBLE) {
                        collectingSilverVipLoginEdit.setText(scan_msg);
                    } else {
                        selectGoods(scan_msg);
                    }
                    break;
                case 200:
                    List<GiftGoodsInfo.DataBean.ListBean> l = (List<GiftGoodsInfo.DataBean.ListBean>) data.getSerializableExtra("choose_list");
                    gifts.clear();
                    gifts.addAll(l);
                    for (GiftGoodsInfo.DataBean.ListBean listBean : l) {
                        boolean a = false;
                        int b = 0;
                        for (int i = 0; i < selectList.size(); i++) {
                            if (listBean.getGoods_gifts_id().equals(selectList.get(i).getGift_id())) {
                                a = true;
                                b = i;
                            }
                        }
                        if (a) {
                            selectList.get(b).setAgoods_count((double) listBean.getChooseNum());
                        } else {
                            GoodBean.DataBean.GoodsBean goodsBean = new GoodBean.DataBean.GoodsBean(listBean);
                            selectList.add(goodsBean);
                        }
                    }
                    giftGoodsNum = data.getIntExtra("allChooseNum", 0);
                    setSelectedAdapter();
                    countMoney();
                    break;
                case 300:
                    GoodBean.DataBean.GoodsBean bean = (GoodBean.DataBean.GoodsBean) data.getSerializableExtra("bean");
                    int index = -1;
                    for (int s = 0; s < selectList.size(); s++) {
                        if (bean.getId().equals(selectList.get(s).getId())) {
                            if ("2".equals(bean.getAttribute_state())) {
                                for (int i = 0; i < selectList.get(s).getSkuList().size(); i++) {
                                    if (bean.getSkuList().get(0).getId().equals(selectList.get(s).getSkuList().get(i).getId())) {
                                        index = s;
                                        break;
                                    }
                                }
                            } else {
                                index = s;
                                break;
                            }
                        }
                    }
                    llSku.setVisibility(View.GONE);
                    if (index != -1) {
                        if ("1".equals(bean.getSerial_number_state())) {
                            if (bean.getSerialList().size() == 0) {
                                selectList.remove(index);
                            } else {
                                selectList.set(index, bean);
                            }
                        } else {
                            selectList.set(index, bean);
                        }
                    } else {
                        selectList.add(bean);
                    }
                    setSelectedAdapter();
                    countMoney();
                    break;
            }
        }
    }

    private List<GiftGoodsInfo.DataBean.ListBean> gifts = new ArrayList<>();

    //
    private void GetGoodList(String goodsId) {
        if(classList.size() == 0){
            showLoad();
        }else{
            loadingDialog.show();
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("page", page);
            jsonObject.put("goods_id", goodsId);
            jsonObject.put("serial_number_state", "1");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        jsonObject = Tools.createParameterCode(jsonObject);
        HttpUtils.post(context, Common.GET_GOODS, jsonObject, new TextCallBack() {
            @Override
            protected void onSuccess(String text) {
                goodBean = GsonUtils.JsonToBean(text, GoodBean.class);
                Message msg = new Message();
                if (goodBean.getStatus() == 1) {
                    msg.what = 1;
                } else {
                    msg.what = 2;
                }
                handler.sendMessage(msg);
            }

            @Override
            protected void onFailure(ResponseException e) {
                loadingDialog.dismiss();
                dismissLoad();
            }
        });
    }

    private void placeOrder() {
        JSONObject json = new JSONObject();
        try {
            JSONArray goods = new JSONArray();
            for (int i = 0; i < selectList.size(); i++) {
                JSONObject good = new JSONObject();
                GoodBean.DataBean.GoodsBean g = selectList.get(i);
                if (0 == g.getIs_gift_good()) {//不是贈送商品
                    good.put("id", g.getId());
                    good.put("retail_price", g.getRetail_price());
                    good.put("goods_name", g.getGoods_name());
                    good.put("pricing_method", g.getPricing_method());
                    good.put("attribute_state", g.getAttribute_state());
                    if ("0".equals(g.getId())) {
                        good.put("goods_type", "2");
                    } else {
                        good.put("goods_type", "1");
                    }
                    if ("1".equals(g.getPricing_method())) {
                        good.put("num", g.getAgoods_count());
                    } else {
                        good.put("num", g.getAgoods_count());
                    }
                    good.put("company", g.getCompany());
                    good.put("cashier_manual_discount", g.getSku_discount());
                    if (g.getSkujson() != null && g.getSkujson().size() > 0) {
                        JSONObject json2 = new JSONObject();
                        JSONArray jsArray = new JSONArray();
                        json2.put("id", g.getSkujson().get(0).getId());
                        json2.put("name", g.getSkujson().get(0).getSku());
                        jsArray.put(json2);
                        good.put("sku", jsArray);
                    }
                    good.put("serial_number_state", g.getSerial_number_state());
                    if ("1".equals(g.getSerial_number_state())) {
                        JSONArray serial_list = new JSONArray();
                        for (int s = 0; s < g.getSerialList().size(); s++) {
                            JSONObject j = new JSONObject();
                            GoodBean.DataBean.GoodsBean.SerialBean serialBean = g.getSerialList().get(s);
                            j.put("main_serial_number", serialBean.getMain_serial_number());
                            j.put("auxiliary_serial_number_one", serialBean.getAuxiliary_serial_number_one());
                            j.put("auxiliary_serial_number_two", serialBean.getAuxiliary_serial_number_two());
                            serial_list.put(j);
                        }
                        good.put("serial_list", serial_list);
                    }
                } else {
                    good.put("goods_name", g.getGoods_name());
                    good.put("sku_name", g.getSku_name());
                    good.put("goods_code", g.getGoods_code());
                    good.put("sku_code", g.getSku_code());
                    good.put("goods_number", g.getGoods_number());
                    good.put("sku_num", g.getSku_num());
                    good.put("cost_price", g.getCost_price());
                    good.put("goods_gifts_id", g.getGoods_gifts_id());
                    good.put("remain_inventory", g.getRemain_inventory());
                    good.put("id", g.getId());
                    good.put("sku_id", g.getSku_id());
                    good.put("goods_image", g.getGoods_image());
                    good.put("is_goods_gift", 1);
                    good.put("num", g.getAgoods_count());
                    good.put("goods_gifts_type", 0);
//                    good.put("gifts_id", g.getGift_id());
                }
                if (!"".equals(g.getCheng_price())) {
                    good.put("code_price_state", "1");
                    good.put("original_price", g.getCheng_price());
                }
                goods.put(good);
            }
            json.put("goods_info", goods);
            json = Tools.createParameterCode(json);
            HttpUtils.post(context, Common.PLACE_ORDER, json, new TextCallBack() {
                @Override
                protected void onSuccess(String text) {
                    loadingDialog.dismiss();
                    dismissLoad();
                    Log.e(TAG, "onSuccess: make_order=" + text);
                    try {
                        JSONObject success = new JSONObject(text);
                        if (success.getInt("status") == 1) {
                            String order_no = success.getString("order_no");
                            intent = new Intent(context, ChoosePaymentActivity.class);
                            intent.putExtra("list", (Serializable) selectList);
                            intent.putExtra("allPrice", allPrice);
                            intent.putExtra("order_no", order_no);
                            intent.putExtra("isVip", isVip);
                            intent.putExtra("vipInfo", infoBean);
                            startActivity(intent);
                        } else {
                            Toast.makeText(context, success.getString("msg"), Toast.LENGTH_SHORT).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                protected void onFailure(ResponseException e) {
                    loadingDialog.dismiss();
                    dismissLoad();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /*private void GetVipInfo() {
        loadingDialog.show();
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("vipCode", collectingSilverVipLoginEdit.getText().toString().trim());//card_num
            jsonObject = Tools.createParameterCode(jsonObject);
            HttpUtils.post(context, Common.GET_VIP_INFO, jsonObject, new TextCallBack() {
                @Override
                protected void onSuccess(String text) {
                    loadingDialog.dismiss();
                    vipinfoBean = GsonUtils.JsonToBean(text, VipListBean.class);
                    Toast.makeText(context, vipinfoBean.getMsg(), Toast.LENGTH_SHORT).show();
                    Message msg = new Message();
                    if (vipinfoBean.getStatus() == 1) {
                        collectingSilverVipLoginEdit.setText("");
                        msg.what = 3;
                    } else {
                        msg.what = 4;
                    }
                    handler.sendMessage(msg);
                }

                @Override
                protected void onFailure(ResponseException e) {
                    loadingDialog.dismiss();
                }
            });
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }*/

    public static boolean isNumeric(String str) {
        Pattern pattern = compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }

    private int skuIndex = 0;//掃描規格商品條碼添加規格商品時，第幾個規格

    private void selectGoods(String scan_msg) {
        Log.e(TAG, "selectGoods: scan_msg=" + scan_msg);
        String chengcode = scan_msg;
        boolean ischeng = false;/**判斷是否是大華稱條碼*/
        boolean skuFlag = false;//判斷所有商品中是否包含當前規格商品條碼
        int indexs = -1;

        if (chengcode.length() >= 17 &&
                isNumeric(chengcode)) {
            ischeng = true;
            scan_msg = chengcode.substring(2, 7);
            chengcode = chengcode.substring(0, 17);
            String balanceString = chengcode.substring(12, 17);
        } else {
            scan_msg = chengcode;
        }
        if (chengcode.length() >= 17) {
            ischeng = true;
            scan_msg = chengcode.substring(2, 7);
        } else {
            scan_msg = chengcode;
        }
        boolean have = false;//所有商品中是否包含當前掃描的商品
        if (!ischeng) {
            for (int j = 0; j < selectList.size(); j++) {
                String goods_code = selectList.get(j).getGoods_code();
                String goods_number = selectList.get(j).getGoods_number();
                String goods_name = selectList.get(j).getGoods_name();
                if ("1".equals(selectList.get(j).getPricing_method())) {
                    if (!TextUtils.isEmpty(goods_code) && goods_code.equals(scan_msg)) {
                        indexs = j;
                        have = true;
                        break;
                    }
                    if (!TextUtils.isEmpty(goods_name) && goods_name.equals(scan_msg)) {
                        indexs = j;
                        have = true;
                        break;
                    }
                    if (!TextUtils.isEmpty(goods_number) && goods_number.equals(scan_msg)) {
                        indexs = j;
                        have = true;
                        break;
                    }
                    Gson gson = new Gson();
                    if ("2".equals(selectList.get(j).getAttribute_state())
                            && selectList.get(j).getSkujson() != null
                            && selectList.get(j).getSkujson().size() > 0) {
                        for (int t = 0; t < selectList.get(j).getSkujson().size(); t++) {
                            if (selectList.get(j).getSkujson().get(t).getSku_code() != null && !TextUtils.isEmpty(selectList.get(j).getSkujson().get(t).getSku_code())) {
                                String skucode = selectList.get(j).getSkujson().get(t).getSku_code();
                                String skuGoodsNumber = selectList.get(j).getSkujson().get(t).getSku_goods_number();
                                String skuId = selectList.get(j).getSkujson().get(t).getId();
                                if (skucode.equals(scan_msg)) {
                                    indexs = j;
                                    have = true;
                                    skuFlag = true;
                                    break;
                                } else if (skuGoodsNumber.equals(scan_msg)) {
                                    indexs = j;
                                    have = true;
                                    skuFlag = true;
                                } else if (skuId.equals(scan_msg)) {
                                    indexs = j;
                                    have = true;
                                    skuFlag = true;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (indexs == -1) {
            for (int i = 0; i < classList.size(); i++) {
                for (int s = 0; s < classList.get(i).getGoods().size(); s++) {
                    String goods_code = classList.get(i).getGoods().get(s).getGoods_code();
                    String goods_number = classList.get(i).getGoods().get(s).getGoods_number();
                    String goods_name = classList.get(i).getGoods().get(s).getGoods_name();
                    if (!TextUtils.isEmpty(goods_code) && goods_code.equals(scan_msg)) {
                        class_index = i;
                        goods_index = s;
                        have = true;
                        break;
                    }
                    if (!TextUtils.isEmpty(goods_name) && goods_name.equals(scan_msg)) {
                        class_index = i;
                        goods_index = s;
                        have = true;
                        break;
                    }
                    if (!TextUtils.isEmpty(goods_number) && goods_number.equals(scan_msg)) {
                        class_index = i;
                        goods_index = s;
                        have = true;
                        break;
                    }
//                if (!ischeng) {
//                    if (!TextUtils.isEmpty(goods_code) && goods_code.equals(scan_msg)) {
//                        class_index = i;
//                        goods_index = s;
//                        have = true;
//                        break;
//                    }
//                }
                    if (!ischeng && "2".equals(classList.get(i).getGoods().get(s).getAttribute_state())
                            && classList.get(i).getGoods().get(s).getSkujson() != null
                            && classList.get(i).getGoods().get(s).getSkujson().size() > 0) {
                        for (int t = 0; t < classList.get(i).getGoods().get(s).getSkujson().size(); t++) {
                            if (classList.get(i).getGoods().get(s).getSkujson().get(t).getSku_code() != null && !TextUtils.isEmpty(classList.get(i).getGoods().get(s).getSkujson().get(t).getSku_code())) {
                                String skucode = classList.get(i).getGoods().get(s).getSkujson().get(t).getSku_code();
                                String skuGoodsNumber = classList.get(i).getGoods().get(s).getSkujson().get(t).getSku_goods_number();
                                if (skucode.equals(scan_msg)) {
                                    class_index = i;
                                    goods_index = s;
                                    have = true;
                                    skuFlag = true;
                                    skuIndex = t;
                                    break;
                                } else if (skuGoodsNumber.equals(scan_msg)) {
                                    class_index = i;
                                    goods_index = s;
                                    have = true;
                                    skuFlag = true;
                                    skuIndex = t;
                                }
                            }
                        }
                    }
                }
            }
        }
        Log.e(TAG, "selectGoods: have=" + have);
        if (indexs == -1) {
            if (have) {
                /**
                 * 規格商品
                 * */
                GoodBean.DataBean.GoodsBean gb1 = classList.get(class_index).getGoods().get(goods_index);
                if ("2".equals(gb1.getAttribute_state()) && gb1.getSkujson() != null && gb1.getSkujson().size() > 0) {
                    /**已選擇的*/
                    if (skuFlag) {
                        if ("2".equals(gb1.getPricing_method())) {
                            collectingSilverAddSkuEt.setText("1");
                            collectingSilverAddSkuLinear.setVisibility(View.VISIBLE);
                        } else {
                            GoodBean.DataBean.GoodsBean good1 = new GoodBean.DataBean.GoodsBean();
                            good1.setRetail_price(gb1.getSkujson().get(skuIndex).getRetail_price());
                            good1.setId(gb1.getId());
                            good1.setC_id(gb1.getC_id());
                            good1.setGoods_name(gb1.getGoods_name());
                            good1.setGoods_img(gb1.getGoods_img());
                            good1.setPricing_method(gb1.getPricing_method());
                            good1.setAgoods_count(1.0);
                            good1.setSku_discount(1);
                            good1.setAttribute_state(gb1.getAttribute_state());
                            good1.setVip_retail_state(gb1.getVip_retail_state());
                            good1.setStore_mem_status(gb1.getStore_mem_status());
                            good1.setStore_mem_price(gb1.getStore_mem_price());
                            good1.setPlus_mem_status(gb1.getPlus_mem_status());
                            good1.setPlus_price(gb1.getPlus_price());
                            good1.setPlus_mem_integral(gb1.getPlus_mem_integral());
                            good1.setStore_mem_integral(gb1.getStore_mem_integral());
                            good1.setSerial_number_state(gb1.getSerial_number_state());
                            good1.setSku_name(gb1.getSkujson().get(skuIndex).getSku());
                            List<GoodBean.DataBean.GoodsBean.SkuListBean> array1 = new ArrayList<>();
                            GoodBean.DataBean.GoodsBean.SkuListBean skuJsonBean1 = new GoodBean.DataBean.GoodsBean.SkuListBean();
                            skuJsonBean1.setId(gb1.getSkujson().get(skuIndex).getId());
                            skuJsonBean1.setNum(gb1.getSkujson().get(skuIndex).getNum());
                            skuJsonBean1.setRetail_price(gb1.getSkujson().get(skuIndex).getRetail_price());
                            skuJsonBean1.setSku(gb1.getSkujson().get(skuIndex).getSku());
                            skuJsonBean1.setSku_res(gb1.getSkujson().get(skuIndex).getSku_res());
                            skuJsonBean1.setSku_code(gb1.getSkujson().get(skuIndex).getSku_code());
                            skuJsonBean1.setStore_mem_status(gb1.getSkujson().get(skuIndex).getStore_mem_status());
                            skuJsonBean1.setStore_mem_price(gb1.getSkujson().get(skuIndex).getStore_mem_price());
                            skuJsonBean1.setPlus_price(gb1.getSkujson().get(skuIndex).getPlus_price());
                            skuJsonBean1.setStore_mem_integral(gb1.getSkujson().get(skuIndex).getStore_mem_integral());
                            skuJsonBean1.setPlus_mem_integral(gb1.getSkujson().get(skuIndex).getPlus_mem_integral());
                            skuJsonBean1.setSku_goods_number(gb1.getSkujson().get(skuIndex).getSku_goods_number());
                            array1.add(skuJsonBean1);
                            good1.setSkujson(array1);
                            if ("1".equals(good1.getSerial_number_state())) {
                                intent = new Intent(context, StringCodeOperationActivity.class);
                                intent.putExtra("good", good1);
                                intent.putExtra("operation", 1);
                                startActivityForResult(intent, 300);
                            } else {
                                selectList.add(good1);
                            }
                            allNum = allNum + 1;
                            countMoney();
                        }
                    } else {
                        sku_index = 9999;
                        mMap = new HashMap<>();
                        isSearchGoods = true;
                        llSku.setVisibility(View.VISIBLE);
                        Glide.with(context).load(gb1.getGoods_img()).into(skuPicture);
                        skuName.setText(gb1.getGoods_name());
                        skuPrice.setText(gb1.getRetail_price());
                        SkuAdapter adapter = new SkuAdapter(context, gb1,null);
                        lvSpecificationName.setAdapter(adapter);
                        adapter.onClicked(new SkuAdapter.onListener() {
                            @Override
                            public void getPosition(int position, String path) {
                                //Toast.makeText(context, String.valueOf(position), Toast.LENGTH_SHORT).show();
                                mMap.put(position, path);
                                if (mMap.size() == gb1.getSkuinfo().size()) {
                                    String paths = "";
                                    for (int i = mMap.size() - 1; i >= 0; i--) {
                                        paths = mMap.get(i) + "," + paths;
                                    }
                                    paths = paths.substring(0, paths.length() - 1);
                                    boolean have = false;
                                    for (int i = 0; i < gb1.getSkujson().size(); i++) {
                                        if (paths.equals(gb1.getSkujson().get(i).getSku_res())) {
                                            skuPrice.setText(gb1.getSkujson().get(i).getRetail_price());
                                            have = true;
                                            break;
                                        }
                                    }
                                    if (have) {
                                        sku_index = goods_index;
                                    }
                                }
                            }
                        });
                    }
                } else {
                    if ("2".equals(gb1.getPricing_method())) {
                        if (ischeng) {
                            GoodBean.DataBean.GoodsBean goodsBean = new GoodBean.DataBean.GoodsBean();
                            goodsBean.setPricing_method("2");
                            goodsBean.setC_id(gb1.getC_id());
                            goodsBean.setAgoods_count((Double.parseDouble(chengcode.substring(12, 17)) / 1000));
                            goodsBean.setGoods_img(gb1.getGoods_img());
                            goodsBean.setGoods_number(gb1.getGoods_number());
                            goodsBean.setGoods_name(gb1.getGoods_name());
                            goodsBean.setId(gb1.getId());
                            goodsBean.setGoods_code(gb1.getGoods_code());
                            goodsBean.setCheng_price((Double.parseDouble(chengcode.substring(7, 12)) / 100) + "");
                            goodsBean.setRetail_price(gb1.getRetail_price());
                            goodsBean.setAttribute_state(gb1.getAttribute_state());
                            goodsBean.setVip_retail_state(gb1.getVip_retail_state());
                            goodsBean.setStore_mem_status(gb1.getStore_mem_status());
                            goodsBean.setStore_mem_price(gb1.getStore_mem_price());
                            goodsBean.setPlus_mem_status(gb1.getPlus_mem_status());
                            goodsBean.setPlus_price(gb1.getPlus_price());
                            goodsBean.setStore_mem_integral(gb1.getStore_mem_integral());
                            goodsBean.setPlus_mem_integral(gb1.getPlus_mem_integral());
                            allNum = allNum + 1;
                            selectList.add(goodsBean);
                            setSelectedAdapter();
                            countMoney();
                        } else {
                            weighFlag = 3;
                            weighIndex = goods_index;
                            weighPosition = class_index;
                            chooseGoodBean = new GoodBean.DataBean.GoodsBean(gb1);
                            collectingSilverWeighName.setText(chooseGoodBean.getGoods_name());
                            collectingSilverWeighFreightNumber.setText(chooseGoodBean.getGoods_number());
                            collectingSilverWeighBarcode.setText(chooseGoodBean.getGoods_code());
                            collectingSilverWeighNum.setText("1.0");
                            collectingSilverWeighLinear.setVisibility(View.VISIBLE);
                            collectingSilverWeighNum.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    collectingSilverWeighNum.requestFocus();
                                    collectingSilverWeighNum.setSelection(collectingSilverWeighNum.getText().toString().length());
                                }
                            }, 200);
                        }
                    } else {
                        boolean flag = false;
                        int index = 0;
                        for (int s = 0; s < selectList.size(); s++) {
                            if (gb1.getId().equals(selectList.get(s).getId())) {
                                if ("2".equals(gb1.getAttribute_state())) {
                                    for (int i = 0; i < selectList.get(s).getSkuList().size(); i++) {
                                        if (gb1.getSkuList().get(0).getId().equals(selectList.get(s).getSkuList().get(i).getId())) {
                                            flag = true;
                                            index = s;
                                            break;
                                        }
                                    }
                                } else {
                                    flag = true;
                                    index = s;
                                    break;
                                }
                            }

                        }
                        if ("1".equals(gb1.getSerial_number_state())) {
                            if (flag) {
                                intent = new Intent(context, StringCodeOperationActivity.class);
                                intent.putExtra("good", selectList.get(index));
                                intent.putExtra("operation", 1);
                                startActivityForResult(intent, 300);
                            } else {
                                intent = new Intent(context, StringCodeOperationActivity.class);
                                intent.putExtra("good", gb1);
                                intent.putExtra("operation", 1);
                                startActivityForResult(intent, 300);
                            }
                        } else {
                            if (flag) {
                                selectList.get(index).setAgoods_count(selectList.get(index).getAgoods_count() == null ? 0.0 : selectList.get(index).getAgoods_count() + 1);
                            } else {
                                gb1.setAgoods_count(1.0);
                                selectList.add(gb1);
                            }
                        }
                        setSelectedAdapter();
                        countMoney();
                    }
                }
                collectingSilverSearchEt.setText("");
                collectingSilverSearchEt.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        collectingSilverSearchEt.requestFocus();
                    }
                }, 500);
            } else {
                collectingSilverSearchEt.setText("");
                Toast.makeText(context, "沒有此商品", Toast.LENGTH_SHORT).show();
                collectingSilverSearchEt.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        collectingSilverSearchEt.requestFocus();
                    }
                }, 500);
            }
        } else {
            if (have) {
                /**
                 * 規格商品
                 * */
                GoodBean.DataBean.GoodsBean gb1 = selectList.get(indexs);
                if ("2".equals(gb1.getAttribute_state()) && gb1.getSkujson() != null && gb1.getSkujson().size() > 0) {
                    /**已選擇的*/
                    if (skuFlag) {
                        if ("2".equals(gb1.getPricing_method())) {
                            collectingSilverAddSkuEt.setText("1");
                            collectingSilverAddSkuLinear.setVisibility(View.VISIBLE);
                        } else {
                            if ("1".equals(gb1.getSerial_number_state())) {
                                intent = new Intent(context, StringCodeOperationActivity.class);
                                intent.putExtra("good", gb1);
                                intent.putExtra("operation", 1);
                                startActivityForResult(intent, 300);
                            } else {
                                gb1.setAgoods_count(gb1.getAgoods_count() + 1);
                                selectList.set(indexs, gb1);
                            }
                            allNum = allNum + 1;
                            countMoney();
                        }
                    } else {
                        if ("2".equals(gb1.getAttribute_state())) {
                            llSku.setVisibility(View.VISIBLE);
                        }
                    }
                } else {
                    if ("2".equals(gb1.getPricing_method())) {
                        if (ischeng) {
//                            gb1.setAgoods_count(gb1.getAgoods_count()+1);
//                            selectList.set(indexs,gb1);
                            selectList.add(gb1);
                            setSelectedAdapter();
                            countMoney();
                        } else {
                            weighFlag = 1;
                            weighIndex = indexs;
                            chooseGoodBean = new GoodBean.DataBean.GoodsBean(gb1);
                            collectingSilverWeighName.setText(chooseGoodBean.getGoods_name());
                            collectingSilverWeighFreightNumber.setText(chooseGoodBean.getGoods_number());
                            collectingSilverWeighBarcode.setText(chooseGoodBean.getGoods_code());
                            collectingSilverWeighNum.setText("1.0");
                            collectingSilverWeighLinear.setVisibility(View.VISIBLE);
                            collectingSilverWeighNum.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    collectingSilverWeighNum.requestFocus();
                                    collectingSilverWeighNum.setSelection(collectingSilverWeighNum.getText().toString().length());
                                }
                            }, 500);
                        }
                    } else {
                        if ("1".equals(gb1.getSerial_number_state())) {
                            intent = new Intent(context, StringCodeOperationActivity.class);
                            intent.putExtra("good", selectList.get(indexs));
                            intent.putExtra("operation", 1);
                            startActivityForResult(intent, 300);
                        } else {
                            gb1.setAgoods_count(gb1.getAgoods_count() + 1);
                            selectList.set(indexs, gb1);
                        }
                        setSelectedAdapter();
                        countMoney();
                    }
                }
                collectingSilverSearchEt.setText("");
                collectingSilverSearchEt.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        collectingSilverSearchEt.requestFocus();
                    }
                }, 500);
            }
        }

    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            View v = getCurrentFocus();
            if (isShouldHideInput(v, ev)) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
            }
            return super.dispatchTouchEvent(ev);
        }
        // 必不可少，否則所有的組件都不會有TouchEvent了
        if (getWindow().superDispatchTouchEvent(ev)) {
            return true;
        }
        return onTouchEvent(ev);

    }

    public boolean isShouldHideInput(View v, MotionEvent event) {
        if (v != null && (v instanceof EditText)) {
            int[] leftTop = {0, 0};
            //獲取輸入框當前的location位置
            v.getLocationInWindow(leftTop);
            int left = leftTop[0];
            int top = leftTop[1];
            int bottom = top + v.getHeight();
            int right = left + v.getWidth();
            if (event.getX() > left && event.getX() < right
                    && event.getY() > top && event.getY() < bottom) {
                // 點擊的是輸入框區域，保留點擊EditText的事件
                return false;
            } else {
                return true;
            }
        }
        return false;
    }

    private void initViewColor(){
        if(allNum>0){
            collectionSelectTitle.setTextColor(getResources().getColor(R.color.collectingSilver_yellow));
            collectingSilverChooseGiftNum.setTextColor(getResources().getColor(R.color.collectingSilver_yellow));
            collectingSilverPrice.setTextColor(getResources().getColor(R.color.collectingSilver_yellow));
            collectingSilverSettlement.setBackgroundColor(getResources().getColor(R.color.login_textColor1));
            collectingSilverShopCar.setImageDrawable(getResources().getDrawable(R.mipmap.collecting_card_icon));
        }else{
            collectionSelectTitle.setTextColor(Color.parseColor("#a1a1a1"));
            collectingSilverPrice.setTextColor(Color.parseColor("#b4b4b4"));
            collectingSilverChooseGiftNum.setTextColor(Color.parseColor("#b4b4b4"));
            collectingSilverSettlement.setBackgroundColor(Color.parseColor("#b4b4b4"));
            collectingSilverShopCar.setImageDrawable(getResources().getDrawable(R.mipmap.collecting_card_unselect_icon));
        }
    }

    private TextWatcher mNumberText;
    private void showNumberDialog(GoodBean.DataBean.GoodsBean item){
        mNumberDialog.setVisibility(View.VISIBLE);
        mNumberDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismissNumber();
            }
        });
        mNumberContentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        mNumberBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!mNumberBt.isSelected()){
                    return;
                }
                int value=Integer.parseInt(mNumberEdit.getEditableText().toString());
                if(!isSkuSubmit(item,false,value)){
                    return;
                }
                for (int i = 0; i < selectList.size(); i++) {
                    if(selectList.get(i).getId().equals(item.getId())){
                        selectList.get(i).setAgoods_count((double) value);
                        setNumber(selectList.get(i),value);
                        setSelectedAdapter();
                        countMoney();
                        ToastUtils.s(getApplicationContext(),"修改成功");
                        dismissNumber();
                    }
                }
            }
        });
        if(mNumberText!=null){
            mNumberEdit.removeTextChangedListener(mNumberText);
        }
        mNumberText=new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mNumberBt.setSelected(!s.toString().trim().isEmpty());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        };
        mNumberEdit.addTextChangedListener(mNumberText);
        mNumberEdit.setText("");
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if(mNumberDialog.getVisibility()==View.VISIBLE && event.getKeyCode()==KeyEvent.KEYCODE_BACK){
            if(event.getAction()==KeyEvent.ACTION_UP){
                if(dismissNumber()){
                    return true;
                }
            }
            return true;
        }
        if(mDiscountView.getVisibility()==View.VISIBLE && event.getKeyCode()==KeyEvent.KEYCODE_BACK){
            if(event.getAction()==KeyEvent.ACTION_UP){
                if(dismissDiscount()){
                    return true;
                }
            }
            return true;
        }
        return super.dispatchKeyEvent(event);
    }

    private boolean dismissNumber(){
        if(mNumberDialog.getVisibility()==View.VISIBLE){
            mNumberDialog.setVisibility(View.GONE);
            return true;
        }
        return false;
    } 
    // 显示折扣设置界面。
    public void showDiscountView(GoodBean.DataBean.GoodsBean item){
        mDiscountView.setVisibility(View.VISIBLE);
        discount_edit_name.setText(item.getGoods_name());

          
        onCreateButton(item);
 


        AdapterItemClickListener<Double> listener=new AdapterItemClickListener<Double>() {
            @Override
            public void onItemClick(int position, Double data) {
                edit_discount_edit.setText(data+"");
                edit_discount_bt.setSelected(true);
                double value=data/100.0;
                initDiscountView(item,value);
            }
        };

        
        edit_discount_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SilverDiscountDialog dialog=new SilverDiscountDialog(CollectingSilverActivity.this,listener,edit_discount_edit.getMeasuredWidth());
                dialog.showView(edit_discount_edit);
            }
        });
          Log.e(TAG, "a的值"); 
        //   赋默认值
        // 如果商品的 sku_discount 小于等于 0，则清空 edit_discount_edit 的文本。
        if(item.getSku_discount()<=0){
            edit_discount_edit.setText("");
        }
        // 否则，将 item.getSku_discount() 的值设置为 edit_discount_edit 的文本内容。
        else {
            int a= new Double(item.getSku_discount()*100.0).intValue();
            // 我下个打印一下这个a的值
            // Log.e("a的值",a+"");
             Log.e(TAG, "a的值" + a);
            if(a==100){
                edit_discount_edit.setText("");
            }else {
                edit_discount_edit.setText(a+"");
            }

            
          // 假设 vipDiscount 是当前的默认折扣值，例如 "90" 表示 90 折 
    
     // 遍历折扣按钮列表，找到与默认折扣值匹配的按钮
    for (Button button : discountButtons) {
        String buttonText = button.getText().toString().replace("折", "");

        Log.e(TAG, "onSuccess: 8269" + buttonText + "分开" + String.valueOf(a));
        if (buttonText.equals(String.valueOf(a))) { // 使用 equals 方法比较字符串内容
             Log.e(TAG, "找到相同了的");
            // 设置当前按钮为选中状态
            button.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.selected_button_background));
        } else {
            // 设置其他按钮为默认状态
            button.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.default_button_background));
        }
    }
        }
        initDiscountView(item,item.getSku_discount());
        mDiscountContentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        mDiscountView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismissDiscount();
            }
        });
        mDiscountTitleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        edit_discount_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!edit_discount_bt.isSelected()){
                    return;
                }

                double value=KotlinUtils.INSTANCE.getTextNumber(edit_discount_edit)/100.0;
                for (int i = 0; i < selectList.size(); i++) {
                    if(selectList.get(i).getId().equals(item.getId())){
                        selectList.get(i).setSku_discount(value);
                        setSelectedAdapter();
                        countMoney();
                        ToastUtils.s(getApplicationContext(),"修改成功");
                        dismissDiscount();
                    }
                }
            }
        });
    }
    private boolean dismissDiscount(){
        if(mDiscountView.getVisibility()==View.VISIBLE){
            mDiscountView.setVisibility(View.GONE);
            return true;
        }
        return false;
    }
    private void initDiscountView(GoodBean.DataBean.GoodsBean item,double discount){
        HashMap<String,Object> map=selectedAdapter.getDiscountValue(item,discount+"");
        boolean isSucess= (boolean) map.get("isSucess");
        double discountAmount= (double) map.get("discountAmount");
        double discountAmountNew= (double) map.get("discountAmountNew");
        String msg= (String) map.get("msg");
        double countAmount= (double) map.get("countAmount");
        String value= (String) map.get("value");
        discount_edit_price.setText("$ "+countAmount);
        if(discountAmount<=0){
            if(KotlinUtils.INSTANCE.isTextNotBlank(edit_discount_edit)){
                edit_discount_amount_edit.setText("$ "+discountAmount);
            }else {
                edit_discount_amount_edit.setText("");
            }
        }else{
            edit_discount_amount_edit.setText("$ "+discountAmount);
        }
        if(isSucess){
            edit_discount_tip.setText("");
            edit_discount_tip.setVisibility(View.GONE);
        }else {
            edit_discount_tip.setText(value);
            edit_discount_tip.setVisibility(View.GONE);
        }
    }
}
